I want to repeat the title of my Wordpress page in a copyright statement in the footer, like

© 2020 "Review: Winter's Sunshine": The Berlin Review Magazine

The snippet I simply used in the past was:

© <?php echo date("Y"); ?> "<?php echo get_the_title(); ?>": [Website Name]

It worked exactly as I needed it.

Unfortunately - due to an exotic page builder - the website I'm currently working on doesn't always use the_title for the h1 headline. Sometimes the_title is ignored and there's a h1-headline somewhere in the html text below.

So, I think I need a function which checks if the_title is empty - if not empty, echoes the_title, and that's it.

But if the_title is empty or non-existing, 2. a. it should hide the complete empty <h1></h1> tag of the title (if it exists), b. look for another, non-empty h1-tag in the html text of the page, c. then echo that tag-content.

I came thus far:

$newtitle = h1 -> outercontent;
if (the_title()){ echo get_the_title(); }
else { echo $newtitle; }

Not very impressive, I'm afraid. Every help would be appreciated.

1 Answer 1


You can't do if(the_title()) cuz the_title() this code'll echo a value... Use get_the_title() for a return of the value.

Remove this code too: $newtitle = h1 -> outercontent;

Do this for check if title is empty:

    // Is empty
} else {
    // is not empty

Or you can do only this:

    // I'm not empty, write your h1 code and title

You can do this too:

$title = !empty(get_the_title()) ? '<h1>' . get_the_title() . '</h1>' : '';
echo $title;
  • Cool, thank you! I love the elegance of the last one, though, there's still the problem, how do I get the content of the h1 tag, if not in "the_title"?
    – HSF
    Dec 25, 2019 at 2:07
  • Can you show me in your admin where the title is please? You can send me your image with WeTransfert. Take a link for the download and share me this link please :) (PS: Sorry for my bad english hehe)
    – Samuel T
    Dec 25, 2019 at 20:19
  • I show you two links. Please see the last footer line. 1. Here it's working, because the headline is in the title_tag: photovoltaiksolarstrom.com/start/photovoltaiklexikon/… . 2. Here, it doesn't work, because the title_tag is empty and the headline is in another h1-tag: photovoltaiksolarstrom.com/photovoltaik-angebotsvergleich .
    – HSF
    Dec 28, 2019 at 11:11
  • This is the code I used: "<?php $title = !empty(get_the_title()) ? '<span>' . get_the_title() . '</span>' : ''; echo $title; ?>"
    – HSF
    Dec 28, 2019 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.