Usually within WordPress a post title will link to the individual post page and if you wanted an external link a visitor would then have to click onto this page and use a link embedded within the post to head to the external URL.

Wouldn’t it be great to save the hassle and have the post title link directly to the URL in question? Here’s how to do it:

Firstly open up and edit the theme function.php adding the following code:

function agentwp_print_post_title() {
$external_url = get_post_meta(get_the_ID(), ‘external_url’, true);
if (empty($external_url)) {
$link = get_permalink();
} else {
$link = $external_url;
}
echo ‘<h2><a href=”‘.$link.‘”>’.get_the_title().‘</a></h2>’;
}

Save this and then edit the index.php or home.php, whichever your particular theme uses, and find this html code:

<h2><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>“><?php the_title(); ?></a></h2>

And replace it with:

<?php madfrog_print_post_title(); ?>

Replacing the madfrog with your theme name, now your theme is good to go. To create a post with an external page title link, head over to the post edit screen and enter the post title as usual. Below the main edit window is the custom fields box, use this to create a custom field with name external_url and in the value field, add the external link URL. The title for this post will now link to the URL you entered in the value part of the custom field.

.