How to Create Replacement Page Titles in WordPress

Oct 22nd, 2009 by RobBarrett in tutorial, wordpress

Here’s a quick tutorial showing how to replace your Page titles in WordPress with custom values different to those shown in your site’s navigation. Sorry about the poor sound quality — I wasn’t speaking from inside a cave, I just had the wrong levels set for my microphone!

In case you can’t make out the code that’s being written in the screencast, you can copy and paste from below…

In header.php, replace your <title> tag with this:

<?php $rpt = get_post_meta($post->ID, 'Replacement_Page_Title', true); ?>
<title>
<?php if ($rpt) { echo $rpt . " &laquo; "; }
else { wp_title('&laquo;', true, 'right'); }; ?> <?php bloginfo('name'); ?></title>

In page.php, replace your Page Title code with this:

<?php $rpt = get_post_meta($post->ID, 'Replacement_Page_Title', true); ?>
<h2><?php if ($rpt) { echo $rpt; } else { the_title(); }; ?></h2>

1 Comment

 

Comments have been closed for this post.