[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

This topic contains 16 replies, has 4 voices, and was last updated by  David 1 month, 4 weeks ago.

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.

    GeneratePress 2.2.2
    GP Premium 1.7.7
    #807502

    Tom 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 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 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 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 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 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 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.