Allow title overwrite on your WordPress blog

September 10, 2009 at 7:40 pm

The the_title(); function allow you to simply display the title of a post or page. Sometimes, you may need to be able to overwrite this function and use a custom title. here is how to do it, using a custom field.

Nothing hard with this recipe: Simply paste th following code on your single.php and page.php, where you want the post/page title to be displayed.

<?php $title = get_post_meta($post->ID, "custom-title", true); 
if ($title != "") {
echo "<h1>".$title."</h1>";
} else { ?>
<h1><?php the_title(); ?></h1>
<?php } ?>

Once done, you just have to create a custom field named custom-title and type your custom title as a value.