Forums

[resolved] Excluding automatic excerpts (3 posts)

  1. semisara
    Member
    Posted 9 months ago #

    Hiya,

    I've searched around for info regarding this question but can't seem to find anything.

    The magazine theme I'm using utilises excerpts (both custom and automatically-generated) on the front page, which isn't a problem. On single entry pages, I'd like to use custom excerpt text as a standfirst/kicker below the entry title, but don't want to go back and write custom excerpts for the hundreds of posts that already exist.

    Is there any way to have only custom excerpts display on single entry pages, while entries that have auto excerpts display nothing?

    Could this be done with existing WordPress codex? I saw something on this website that added new excerpt options through the functions.php file... is this a potential way?

  2. stvwlf
    Member
    Posted 9 months ago #

    Try this (I didn't test it).

    In the template file for the single post page (usually single.php)
    add this below the code that displays the entry title

    <?php if ( has_excerpt() ) {
       <div class="standfirst">
          the_excerpt();
       </div>
    } ?>

    If there is a manual excerpt on a post, that code should display it.
    I wrapped it in a div so you can style the displayed content as desired.

    If there is no manual excerpt nothing will display.

  3. semisara
    Member
    Posted 9 months ago #

    Thank you very much! That works perfectly :)

    If anyone else stumbles upon this with the same question, after receiving your answer I also found the sites below:

    Display the_excerpt only if there is text

    Check if post has the_excerpt

    If the_excerpt() is blank?

Reply

You must log in to post.

About this Topic