WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I do a post or a page with no title, I'm left with an empty h1 tag at the top of the post/page.

I'd like to either get rid of the h1 in these cases, or else be able to add an extra CSS class to the post/page so that I can specify how to display the post (and the h1) differently when the post/page is published with no title.

Are either of these things possible?


share|improve this question
up vote 4 down vote accepted

To add an extra class when there is no title

<h1<?php if(!get_the_title()){echo ' class="no-title"';}?>><?php the_title();?></h1>

Or to only display h1 tags when there is a title

<?php if(get_the_title()) { ?>
    <h1><?php the_title();?></h1>
<?php }?>
share|improve this answer
Perfect. Thanks! – snthr May 15 '11 at 23:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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