Dukeo » WordPress » Overwrite Titles: How To Do This for Blog Posts and Pages

Overwrite Titles: How To Do This for Blog Posts and Pages

Steven 2 responses WordPress

In WordPress default themes’ templates, the the_title() function is used to display the posts and pages’ titles. From time to time, you may need to overwrite your posts’ titles. The easiest way to do that is to use a custom field.

First thing to do is edit the single.php and page.php files of your WordPress theme. Search for:

<h1><?php the_title(); ?></h1>

and replace it with:

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

Once the changes are made in your files, all you need to do is create a custom field named custom-title in your blog post and add your custom title as value.

If you enjoyed this article,
Get email updates

Join for Free »


  1. I am assuming based on just glancing at the code that if you do not add a custom field title value then the original title of the post is displayed. If I were to add the custom value I could title it anything I want. A sort of option of switching back and forth quick and easy. Nice tip or trick.

  2. Grady Pruitt

    Not quite sure why I’d need to do that, but if I ever needed to, it’s nice to know you can. Thanks for sharing!