[Resolved] Remove Excerpt from Archive Page and Add Excerpt to Single Post

Home Forums Support [Resolved] Remove Excerpt from Archive Page and Add Excerpt to Single Post

Home Forums Support Remove Excerpt from Archive Page and Add Excerpt to Single Post

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #807209
    Manish

    I need to remove the Excerpts totally from the archive page. Setting the excerpt length to 0 is not helping.

    I also need to add the excerpt below the title on individual posts.

    Please guide how to achieve this.

    #807502
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Setting the excerpt word count to 0 should do the trick: https://www.screencast.com/t/6qBYmlSJi

    Is that not happening for you?

    To add the excerpt below the title on individual posts, you can:

    1. Create a Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
    2. Add this to the content:

    <?php the_excerpt(); ?>

    3. Set the hook to generate_after_entry_title

    4. Check the Execute PHP checkbox.

    5. Set the Display Rules to all single posts.

    #808090
    Manish

    Thanks,

    Adding the excerpt to single post worked fine.

    But setting the ‘Excerpt word count’ to 0 has no effect.

    #808529
    Leo
    Staff
    Customer Support

    Any chance you can link us to the page in question so we can try to see why that option isn’t working?

    I just tried it too and it worked as Tom showed.

    You can edit the original topic and use the private URL field.

    Let us know 🙂

    #808942
    Manish

    Have added the url.
    These are the current blog settings.
    null
    Site is still in development so no cache plugin is active at present.

    #809418
    David
    Staff
    Customer Support

    Hi there,

    are you using the Manual Excerpt meta box to add the excerpt?

    #811023
    Manish

    YES, the standard way to add excerpts.

    #811193
    David
    Staff
    Customer Support

    The Blog settings excerpt length only apply to the auto excerpt that WP generates, not for manual excerpts and read mores as their length is user defined.

    The simplest way would be to use some CSS to hide them from the archive:

    .archive .entry-summary {
        display: none;
    }
    #811201
    Manish

    Any other way?
    This display:none method is not good for SEO. Can backfire with so much text hidden on category/archive pages.

    #811220
    David
    Staff
    Customer Support

    Could give this PHP snippet a try:

    add_filter( 'wp_trim_excerpt', 'db_excerpt_metabox_remove' );
    function db_excerpt_metabox_remove( $excerpt ) {
    	$output = $excerpt;
    	
    	if ( is_archive() && has_excerpt() ) {
    		$output = '';
    	}
    	
    	return $output;
    }
    #811225
    Manish

    This works but leaves a large padding below the title. How to fix it?padding

    #811345
    David
    Staff
    Customer Support

    This method still outputs the entry summary container. So use the CSS i provided before to remove that from display.

    #811846
    Manish

    Works perfectly!
    Many thanks for the fantastic support you guys offer.

    #811888
    David
    Staff
    Customer Support

    Glad we could be of help.

    #815180
    Manish
    add_filter( 'wp_trim_excerpt', 'db_excerpt_metabox_remove' );
    function db_excerpt_metabox_remove( $excerpt ) {
    	$output = $excerpt;
    	
    	if ( is_archive && has_excerpt() ) {
    		$output = '';
    	}
    	
    	return $output;
    }

    I am not sure why but this code removes the excerpts not just from the archive page/category page but also from the single post which we added using the generate_after_entry_title hook.

Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.