Site logo

Archived topic

Remove excerpt from the archive pages

16 replies · Started by Hasan on May 14, 2019

Viewing posts 1–15 of 17

Hi,

Just purchased the pro version of GeneratePress and going to ask a lots of questions, as I am setting up a new photography site!

First question is, how to remove the excerpts completely form the archive pages only? I am using the GeneratePress child theme, and have placed the following code on the functions.php taking from a previous forum post suggestion:


/*
	Remove excerpts from the achrive pages only
*/

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

But nothing happens. The excerpts are showing as the same.

I've set the excerpt length to 0, which is showing "..." and the "read more" link ("show story" in my case). The excerpts are being generated automatically.

Please suggest. Thanks for your help!

Regards,
Hasan

Hi there,

you won't need that filter function, thats solely if you're using a manual excerpt.

The '...' are displayed because of the Read More.
Do you want the read more button showing?

Thanks David!

I want to remove both the "..." and the read more link.

Best regards,
Hasan

Remove the Read more text from the Read More Label in the Customizer so it is empty. This will remove both.

That worked perfectly!

Thanks David!! :)

You're welcome

If I want to delete "..." but keep the read more button, what should I do?

It lost the excerpt section by using the .entry-summary class. I just want to remove the "..." character?

Any chance you can open a new topic in this case?

Thanks :)

Hello,
I would like to remove the excerpt completely, including the wrapper html element. Available wordpress functions that I am able to find show only how to remove the text within the excerpt markup, not the markup itself.

Pre get posts allows to replace the template with another template ... which is simply more complex way of adding the modified archive.php in child.

I would like to avoid having to create archive.php in my childtheme to do this, and would prefer the hook, function approach. I want to remove html elements that have no purpose from the page for various reasons including accesibility purpose.
Am I missing some method?

PhP preg replace?

Thanks in advance.

Thanks David,
for now I will do it like this, and do some more testing for accessibility. JS is not perfect, but apparently sreen readers "talk" to js. If it shows as a not good solution will revert to elements. :)

add_filter( 'the_excerpt', 'filter_the_excerpt', 10, 2 );
    function filter_the_excerpt( ) {
		if ( 'people' === get_post_type() && ! is_singular() ) {
			return;
		}
}

add_action('wp_footer', 'remove_excerpt_wrapper');
function remove_excerpt_wrapper() {
	if ( 'people' === get_post_type() && ! is_singular() ) {	
		?>
		<script type="text/javascript">
			const postExcerpts = document.querySelectorAll( ".entry-summary" );	
			postExcerpts.forEach(( element ) => { element.parentNode.removeChild( element ); });
		</script>
		<?php
	}
}

As a note - display: none; of visibility: hidden; is ignored by a Screen reader.
But it is something we need to address and get rid of superfluous HTML - its on our list :)

Hope that works for you.

Thanks,

now that you say I think I read this somewhere.
Cool I will add that for a kind of gracefull degradation. :D
If js does not work it will still be ok.

Enjoy

This archived topic is closed to new replies.