[Resolved] Remove custom excerpt but keep read more text

Home Forums Support [Resolved] Remove custom excerpt but keep read more text

Home Forums Support Remove custom excerpt but keep read more text

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1281414
    Joshua

    Hi!

    How can I remove the custom excerpt from the blog archive page, but leave the read more text?

    I add this into my functions.php:

    
    function remove_image_size_attributes( $html ) {
    return preg_replace( '/(width|height)="\d*"/', '', $html );
    }
    
    add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
    function tu_excerpt_metabox_more( $excerpt ) {
        $output = $excerpt;	
    
        if ( has_excerpt() ) {
            $output = sprintf( '%1$s <a href="%2$s">%3$s</a>',
                $excerpt,
                get_permalink(),
                __( 'Read more', 'generatepress' )
            );
        }
    
        return $output;
    }

    And that allows the read more button to show with the custom excerpt. However, I don’t want the custom excerpt to show on the main blog archive page.

    Things I’ve tried so far:

    • Setting Excerpt word count to 0 in Customizer (it still shows the excerpt)
    • Hiding the excerpt using CSS (this hides the read more button as well)
    #1281415
    Leo
    Staff
    Customer Support

    Hi there,

    Are you referring to the custom excerpt added in the metabox?
    https://www.wpbeginner.com/plugins/how-to-customize-wordpress-excerpts-no-coding-required/

    If so then the best solution would be remove the content in the metabox then the customizer option would work.

    #1281416
    Joshua

    Hi Leo!

    This would work, however, I am still using the excerpt on my blog post underneath the title.

    Any other ideas?

    #1281420
    Joshua

    I guess I could create a custom field for my blog post to use in place of the excerpt?

    #1281422
    Leo
    Staff
    Customer Support

    Unfortunately it’s not possible to only remove the excerpt on the archive page with CSS.

    So you are using the excerpt metabox so that you can insert that in page hero?

    If so try using the custom field instead as a workaround:
    https://docs.generatepress.com/article/header-element-template-tags/#custom_field-name

    #1281423
    Joshua

    Got it. That solution works perfectly fine. Thanks so much!

    #1281426
    Leo
    Staff
    Customer Support

    No problem 🙂

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