[Resolved] Remove excerpt from the archive pages

Home Forums Support [Resolved] Remove excerpt from the archive pages

Home Forums Support Remove excerpt from the archive pages

  • This topic has 16 replies, 4 voices, and was last updated 2 years ago by Elvis.
Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #898902
    Hasan

    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

    #898915
    David
    Staff
    Customer Support

    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?

    #899051
    Hasan

    Thanks David!

    I want to remove both the “…” and the read more link.

    Best regards,
    Hasan

    #899056
    David
    Staff
    Customer Support

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

    #899073
    Hasan

    That worked perfectly!

    Thanks David!! πŸ™‚

    #899075
    David
    Staff
    Customer Support

    You’re welcome

    #1555263
    Quan

    If I want to delete “…” but keep the read more button, what should I do?

    #1555277
    Leo
    Staff
    Customer Support

    Try this CSS:

    .entry-summary p:not(.read-more-container) {
        display: none;
    }

    Adding CSS: https://docs.generatepress.com/article/adding-css/

    #1555290
    Quan

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

    #1555618
    Leo
    Staff
    Customer Support

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

    Thanks πŸ™‚

    #2104027
    Elvis

    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.

    #2104037
    David
    Staff
    Customer Support

    Hi there,

    unfortunately there is no filter to remove the HTML at this time.
    You would have to replace the content template – or you can use a Block Element – Content template if you want to avoid PHP in a child theme:

    https://docs.generatepress.com/article/block-element-content-template/

    #2104131
    Elvis

    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
    	}
    }
    #2104155
    David
    Staff
    Customer Support

    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.

    #2104383
    Elvis

    Thanks,

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

    Enjoy

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