I’m trying to print the posts’ parent title on the page as well as the post title for that page. This is how my content-page.php template currently renders the page title.
the_title( '<header class="entry-header"><h1 class="entry-title">', '</h1></header><!-- .entry-header -->' );
I realise I can retrieve the posts’ parent title by doing this:
$parent_title = get_the_title($post->post_parent);
echo $parent_title;
Is there anyway I can slip that code in between the_title parameters, so my parent title and my post title are both wrapped by that h1
element?
Any help is appreciated. Thanks in advance!
You can just add a check:
or use
setup_postdata()
:I would just filter
the_title
:You could just output the header around the title without using the
$before
and$after
parameters:If you insist on using
$before
and$after
, just pass the parent title to either one of the arguments:or