Get wordpress parent page or post title

January 28, 2009 · Print This Article

If you use pages and subpages or posts and parent posts on your WordPress blog, it should be a good idea to display parent page/post title while on a child page.

Here’s a code to do that job easily.

To achieve this recipe, simply edit your page.php file and paste the following code where you’d like your parent page title to be displayed:

<?php
$parent_title = get_the_title($post->post_parent);
echo $parent_title;
?>

That’s all. Also, this code should be some inspiration for creating breadcrumbs.


Related articles:

Your choice for site templates and wordpress themes

Comments

One Response to “Get wordpress parent page or post title”

  1. aduran on April 21st, 2010 12:19 pm

    This is great, I was trying hard to figure out how to have access to a parent page and this did the job, that encouraged me to sign up here and subscribe to your RSS

    Thanks a lot!

Got something to say?

You must be logged in to post a comment.