Site logo

Archived topic

Remove Excerpt from Archive Page and Add Excerpt to Single Post

16 replies · Started by Manish on February 11, 2019

Viewing posts 1–15 of 17

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.

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.

Thanks,

Adding the excerpt to single post worked fine.

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

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 :)

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

Hi there,

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

YES, the standard way to add excerpts.

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;
}

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

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;
}

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

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

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

Glad we could be of help.

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.

This archived topic is closed to new replies.