In a project I’m working on at the moment, The page structure is set up using 5 main pages, and then each have their respective sub-pages. For SEO purposes, I wanted my <title> meta tag to display the page title and it’s parent page title if the current page was a child page, i.e.:
<title>Page Title</title> or <title>Parent Page Title — Page Title</title>
So after doing a little searching and combining some code, this is what I came up with:
<title><?php
if($post->post_parent) {
$parent_title = get_the_title($post->post_parent);
echo $parent_title.' — ';
} ?>
<?php wp_title(''); ?>
</title>

10:48 pm
//
Web Designer Kent
Ive been working on CSS based sites for sometime but still get the odd error in firefox ! wish they just played ball the same when designing, would make life a whole lot easier for everyone involved… but then that would be to simple and obvious…lol
9:33 am
//
Title Posting With Title Parent « CP - Contek Pakai
[...] mempunyai judul satu halaman dengan menyertakan halaman induknya. La aku nyoba googling dan menu di sini dan secara singkat aku Copy Paste code yang ada di bawah ini file page.php. <?php [...]
9:47 am
//
Evan
Thanks! This helped.
1:06 pm
//
Josef
thanks! been looking for a way to display the page parent title.
8:18 am
//
neel
Thanks for this cool tip.. it helps me when i create tabs of subpages from a parent page.
12:37 pm
//
Ion
Thanks! exactly what was looking for
12:24 pm
//
Adam
Magic, thankyou
9:31 pm
//
niki
where do I put the code? I’m also a little confused with each post I do. Am I going to have to change this code everytime I make a new child page.
11:13 pm
//
Tammy Hart
This should go in the header.php template between the tags.
1:30 pm
//
Paris Vega
Tammy to the rescue, again! This also works nice if you need to display the title on the page itself between heading tags.By the way this post is #1 in Google for “wordpress display name of parent page”
9:23 am
//
Graham
Thanks for the clear explanation Tammy – most useful. Does this work inside a WP_Query setup do you know?
8:29 pm
//
Guitar Teacher Kent
can someone help me please im having probems inserting code also, this doesnt make sense at all
11:10 pm
//
Tammy Hart
Kent,
Can you tell me which part you’re having trouble with and hopefully I can help you.
Graham,
Yes, $post->post_parent will work within a WP_query.
2:06 pm
//
kasia
Hi there,
and is there any way to make the parent clickable? also, is it possible to limit parents to one only?
Thanks
Kat
12:00 am
//
Tammy Hart
kasia,
This code is meant to be in the of your document, so you can’t place a link there. Maybe the code here can point you in the right direction: http://www.tammyhartdesigns.com/tutorials/wordpress-how-to-list-child-pages-in-sidebar/
6:04 pm
//
Fafnishart
I’m about to go nuts in here…I can’t get it to work properly. I am still a PHP rookie and need some advice…Please help me Tammy.
I have no “header.php” within my theme files and simply have no idea what file to use amongst my “layouts” directory…
I’d greatly appreciate your help. Thanks in advance!
7:24 pm
//
Tammy Hart
Fafnishart,
Sounds like you have an overly complicated theme. I really wouldn’t be able to tell you what template to use without looking at the theme files myself. Send a list of the directory, or like a screenshot that shows all the files to tammy AT this-domain.
11:42 am
//
Amp
Great code that works fine.
Thanks. But what if you have a static homepage? Could you use the is_front_page statement? I’ve tried it with WP 3.1 but with no luck. Then again, I’m not too great with PHP.
Thanks again!
11:51 am
//
Tammy Hart
Amp,
Not sure what you’re referring to here. This code looks to see if the current page is a child of another page and if that’s true, it adds the parent’s page title to the title tag.
12:05 pm
//
Amp
What I mean is this;
my generic title tag content:
» Archive
If I replace that code with your code then the post title of the static home page is missing. What you get is the URI of the blog as meta title.
Does this make any sense?
BTW, thanks for your quick response.
12:06 pm
//
Amp
Sorry, forgot the code tag.
Generic title content:
» Archive
12:08 pm
//
Amp
Guess that’s not supported.
Anyways, it’s plain WP theme title content.
12:16 pm
//
Tammy Hart
Amp, this code isn’t meant to replace your title tag code entirely, it’s only an example. I suggest using it in addition to several if else statements for different areas of your site. For instance, my title tag on my site is 17 lines of code.
1:50 pm
//
Amp
I understand. I suppose I was trying to get you to give me some nice code for free.
Thanks again for the code and for your reply.
8:52 pm
//
Manny
Hi Tammy, excellent tip.. tammy i need help, i need change a code but i am not expert i need change this code
$postheader .= ” . get_comments_number() . ”;
This function displays the number of comments of the post, sooo i need to change this funsion for showing the category of where the post ..I hope you can help me, thanks in advanced.
9:15 am
//
Tammy Hart
So you need to return the categories, rather than echo them. That would be get_the_category_list(): http://codex.wordpress.org/Function_Reference/get_the_category_list
8:42 am
//
Chris Wiegman
Thank you! I am working on a simple enough site, but they wanted a breadcrumb shown and this is exactly what I needed for the template file