0

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.

4

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 }?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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