Support » Theme: Twenty Nineteen » How to remove Excerpt if left empty?

  • Resolved ironlion37



    I want the twenty nineteen theme to display nothing in the excerpt field if no custom excerpt is entered. In other words, I don’t want it to automatically create an excerpt from the content. Everything I can find says to use this in fucntions.php, but it seems to have no effect in twenty-nineteen:

    remove_filter( ‘get_the_excerpt’, ‘wp_trim_excerpt’ );

    Any suggestions?


Viewing 6 replies - 1 through 6 (of 6 total)
  • You’d want to create a child theme first if you haven’t already so that your changes don’t get overwritten in the future:

    Once you have that setup, copy over /wp-content/themes/twentynineteen/template-parts/content/content-excerpt.php into your child theme. Find this section of code in that file

    <div class="entry-content">
    		<?php the_excerpt(); ?>
    	</div><!-- .entry-content -->

    And change it to the following

    <div class="entry-content">
    		<?php if ( has_excerpt() ) { the_excerpt(); } else { echo ''; } ?>
    	</div><!-- .entry-content -->

    I really appreciate you taking the time respond. Unfortunately that code seems to have no effect. I reproduced the folder structure in the child theme (/template-parts/content/content-excerpt.php) and made the code change, cleared all caches and it’s still behaving exactly the same. It just generates an excerpt from the content when the excerpt input is blank.

    Edit: I should mention that this is multi-site install. I’ve double checked that the site in question is using the child theme. However, I can’t see any evidence that the edited content-excerpt.php file is being picked up.

    Are you sure that’s the right file? In its description it says “Template part for displaying post archives and search results.” I’m not talking about excerpt display in archives or search results…

    Edit 2: I think the problem with this solution is that the template is still creating an excerpt and so the “if, else” statement doesn’t do anything because the template has already created excerpt content automatically.

    • This reply was modified 1 year, 1 month ago by ironlion37.
    • This reply was modified 1 year, 1 month ago by ironlion37.
    • This reply was modified 1 year, 1 month ago by ironlion37.

    Hi again, I think I’ve narrowed this down to a plugin. Please disregard.

    Ok great! 🙂

    Thanks Jarrett! For anyone that comes across this, adding this line to the twenty-nineteen child theme does work to prevent excerpts when the excerpt input is left blank:

    remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );

    And here’s a link to a ready made twenty nineteen child theme if anyone needs it:
    [removed link]

    Moderator Ipstenu (Mika Epstein)


    🏳️‍🌈 Plugin Review Team Rep

    @ironlion37 I’m sure you meant well, but generally asking people to download from your personal site like that should be avoided. If you want to put up a child theme with that on Github, that would be cool. Sadly, too many evil people have abused ‘just download this!’ for us to trust them blindly 🙁

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to remove Excerpt if left empty?’ is closed to new replies.