DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

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.

One Comment

  1. This is along the lines of what im looking for but I would like to remove the title us a filter or hook. Anyone have any idea what I could do to work this using the functions.php file only?

Leave a Comment

Your email address will not be published. Required fields are marked *