How to: Show parent page title regardless of what subpage you are on

October 30, 2009 at 9:47 am

Althougt it may sound simple to advanced WordPress coders, I had many requests from people working with WordPress as a CMS and wanting to be easily able to display parent page title on a subpage.

Nothing hard at all: Just paste the following code where you’d like to display the parent page title:

<?php
if($post->post_parent) {
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
} else {
    wp_title(''); 
}
?>

That’s all! Quick and easy, as we like :)

This recipe has been submitted by Wes Bos. Have WordPress skills? Feel free to contribute to WpRecipes!

Tags: