Archived topic
force read more button
7 replies · Started by Marco on May 23, 2019
Hello
I'm showing my posts in some grid view with a summary and "continue reading..." button - I've some post where the summary is actually too short so WP is not showing a read more button - for layout consistency I'd like to have that read more button on ALL posts - how can I force WP to show the button all the time??
Hi there,
Can you try this snippet here and see if it works?
https://docs.generatepress.com/article/activating-read-custom-excerpt/#read-more-button
Let me know :)
Thanks Leo - just tried that before you responded - it doesn't seem to work - has_excerpt() is always false??
Give this a shot:
https://generatepress.com/forums/topic/read-more-in-case-of-no-excerpt/
Thanks again Leo - the following two filter will do the trick as well:
/* Filter - Remove default 'excerpt more'
---------------------------------------------------------------------------- */
function themeprefix_excerpt_more( $more ) {
return '';
}
add_filter('excerpt_more', 'themeprefix_excerpt_more', 21 );
/* Filter - Add 'read more' to custom excerpt
---------------------------------------------------------------------------- */
function themeprefix_get_the_excerpt( $excerpt ) {
$output = $excerpt;
$output = sprintf(
'%1$s <p class="read-more-container"><a class="button read-more" href="%2$s" title="">%3$s</a></p>',
$excerpt,
get_permalink(),
__( 'Continue Reading', 'plugin' )
);
return $output;
}
add_filter( 'get_the_excerpt', 'themeprefix_get_the_excerpt' );
Awesome.
Thanks for sharing!
Hi, I would like to do the same thing then Marco, can someone could tell me where I have to paste the code he publish ? thank you