Archived topic
Remove custom excerpt but keep read more text
6 replies · Started by Joshua on May 12, 2020
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 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.
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?
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
Got it. That solution works perfectly fine. Thanks so much!
No problem :)