Home / functions.php / Post title to external source
  • How to Post title to external source

    no thumbnail sorry: Post title to external source

    Add the first block of PHP code to your functions.php of your wordpress theme then replace the default title code within your index.php file. Once this is done if you wish to link directly to an external resource add a URL to the custom field title_url.

    ( click code to copy )

    wordpress snippet : PHP - functions.php

    <>
    function print_post_title() {
    	global $post;
        $thePostID = $post->ID;
        $post_id = get_post($thePostID);
        $title = $post_id->post_title;
        $perm = get_permalink($post_id);
        $post_keys = array(); $post_val = array();
        $post_keys = get_post_custom_keys($thePostID);
        if (!empty($post_keys)) {
    		foreach ($post_keys as $pkey) {
    			if ($pkey=='title_url') {
    				$post_val = get_post_custom_values($pkey);
    			}
    		}
    		if (empty($post_val)) {
    			$link = $perm;
    		} else {
    			$link = $post_val[0];
    		}
        } else {
    		$link = $perm;
        }
        echo '<h2><a href="'.$link.'" rel="bookmark" title="'.$title.'">'.$title.'</a></h2>';
    }
    
    ( click code to copy )

    wordpress snippet : PHP - index.php

    <>
    <?php
              print_post_title();
    ?>
    

    ( WordPress codex functions, hooks, in this snippet. )

    get_permalink, get_post, get_post_custom, get_post_custom_keys, get_post_custom_values,