Site logo

Archived topic

Remove custom excerpt but keep read more text

6 replies · Started by Joshua on May 12, 2020

Viewing posts 1–7 of 7

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)

Hi Leo!

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

Any other ideas?

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

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

No problem :)

This archived topic is closed to new replies.