Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

Thanks.

share|improve this question
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.