WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How do I know if a post has a title? (3 posts)

  1. tommorris
    Member
    Posted 8 years ago #

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

  2. Kafkaesqui

    Posted 8 years ago #

    Try:

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

    Even leaner:

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

  3. tommorris
    Member
    Posted 8 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic