Archived topic
Continue Reading button not showing on Archives
9 replies · Started by Glen on December 6, 2022
Example Archives Page: https://www.glenhuff.com/category/social-media-best-practices/page/4/
For some reason, none of the blog posts on an archive page have a "Continue Reading" link after the excerpt. I have the label set in the settings under:
Theme > Customize > Blog > Archives > Read more label = "Continue Reading". Yet, nothing appears. The title links to the single blog posts, but I wanted a read more button after the excerpt. How do I do this?
Hi there,
Can you take a look this first?
https://docs.generatepress.com/article/excerpt-issues/#read-more-label-or-button-not-showing
Thank you. I found a link on that page useful. It sent me to this: https://docs.generatepress.com/article/activating-read-custom-excerpt/
I added the following code to the theme-functons.php file and it worked.
add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
function tu_excerpt_metabox_more( $excerpt ) {
$output = $excerpt;
if ( has_excerpt() ) {
$output = sprintf( '%1$s <p class="read-more-button-container"><a class="button" href="%2$s">%3$s</a></p>',
$excerpt,
get_permalink(),
__( 'Read more', 'generatepress' )
);
}
return $output;
}
Is this something I'll have to add every time the theme updates?
I added the following code to the theme-functons.php file and it worked.
Please do not edit the parent theme's function.php file.
Use one of these methods instead: https://docs.generatepress.com/article/adding-php/
Using a child theme seems like the easiest route. I don't have one installed. Is there a download for the GP child theme?
The Code Snippets plugin suggested is actually the easiest route and the option I would pick if you aren't using a child theme already.
If you prefer to use a child theme: https://docs.generatepress.com/article/using-child-theme/
Okay, I have the child theme installed. My function to show continue reading buttons with excerpts has been added. The archives look great.
But, now I'm seeing a continue reading button on the single post. The theme I'm using displays the excerpt as the first paragraph in a Hero Full-Width fashion.
Example: https://www.glenhuff.com/how-to-create-a-winning-social-media-strategy/
Can you edit the function to this instead?
add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
function tu_excerpt_metabox_more( $excerpt ) {
$output = $excerpt;
if ( has_excerpt() && !is_single() ) {
$output = sprintf( '%1$s <p class="read-more-button-container"><a class="button" href="%2$s">%3$s</a></p>',
$excerpt,
get_permalink(),
__( 'Read more', 'generatepress' )
);
}
return $output;
}
Works perfectly! Thank you.
Glad to help :)