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

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

7 Comments

  1. Great!! Thanks alot!
    Is there a way to make a link too? (link to itself – the parent)

  2. Thanks for the tip! Quick question: Any idea how would you write the function if you wanted to show the root parent page on a grandchild page? I’ve been tinkering, but no cigar (yet).

  3. Thank you!
    Can you explain how can I display not the parent’s titile, but parent’s menu label?

    I’m using All In One Seo pack, where I use special field for menu — its much shorter comparing to long titles.

  4. Please a little help here: this one is bugging me since long time.

    I would like want to display the title of the parent page only if there is one. All the recipes I’ve found so far (including this one) will show the name of the current page when it is a root-level page. This ends up in a double title.

  5. Did you got a way to link to a parent menu ? So I can use this idea as my breadcrumb. Please advice. Thank you.

  6. Hey I got the way :-)
    $parent_title = get_the_title($post->post_parent);
    $parent_link = get_permalink($post->post_parent);
    $parent_title

    Hope this will help some one. Thank you..

  7. Does this work with grandchildren as well?

Leave a Comment

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