Support » Fixing WordPress » How do I know if a post has a title?

  • Resolved tommorris

    (@tommorris)


    Is there any way to get WordPress to tell me whether a post has a title or not. I want to treat posts that have titles differently from those which don’t (see scripting.com for an example).

    Here’s the code I tried:

    <?php $title = the_title();
    if($title != '') { ?>
    …content…
    <? } else { ?>
    …different content…
    <? } ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try:

    <?php if(get_the_title() != '') { ?>
    …content…
    <? } else { ?>
    …different content…
    <? } ?>

    Even leaner:

    <?php if(get_the_title()) { ?>
    …content…
    <? } else { ?>
    …different content…
    <? } ?>

    Thanks. I reread the documentation and found that the_title('', '', false) returns what I want. Thanks for that though, Kafkaesqui.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How do I know if a post has a title?’ is closed to new replies.