- This topic has 7 replies, 4 voices, and was last updated 3 years, 9 months ago by Leo.
-
AuthorPosts
-
January 21, 2018 at 7:28 am #476389Cecilia
I wrote a curated excerpt for a blog post. This makes the Read More-button disappear for that post on the archive page.
Any tip on how to make that button visible again?
The settings in the customizer are:
Excerpt
20 words
Show as buttonThe automatic excerpt is fine, but for some posts I want to use the curated version that I have written for that blog post.
January 21, 2018 at 9:43 am #476456TomLead DeveloperLead DeveloperHi there,
WordPress doesn’t display a read more button when the manual excerpt is used unfortuntely.
However, we can force it to like this:
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-container"><a class="button" href="%2$s">Read more</a></p>', $excerpt, get_permalink() ); } return $output; }
Let me know if you need more info 🙂
January 21, 2018 at 10:25 am #476488CeciliaWorked like clockwork! I just copied the code you sent into my child theme’s functions.php, saved and – voilá!
Thank you!
<3/Cecilia
January 21, 2018 at 9:08 pm #476752TomLead DeveloperLead DeveloperYou’re welcome! 🙂
June 27, 2020 at 7:27 pm #1344105JosephHey Tom,
Thanks for sharing the code.
I am clueless on the tech stuff and only just started my blog. Where do I add the code to get the read button for my post?
Thanks
JoeJune 28, 2020 at 5:58 am #1344350DavidStaffCustomer SupportHi there,
the code is PHP – this article explains:
https://docs.generatepress.com/article/adding-php/
And for reference here is an article relating to this topic:
https://docs.generatepress.com/article/activating-read-custom-excerpt/
June 28, 2020 at 11:05 am #1344701MikeHi Tom,
I used this too – so thanks! I made a couple of changes to suit what I used it for:
1) changed the class to match the read more button in the theme (i noticed my CSS missed…)
2) customized the code to support a different button text on an archive page of a custom post type
I’m new to php so if you notice anything wrong with this please shout!// Add a "Read more..." button for manual excerpts to match that for automatic excerpts // And provide different text for the read more button where post type is 'md' add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' ); function tu_excerpt_metabox_more( $excerpt ) { $output = $excerpt; if ( has_excerpt() && ( 'md' == get_post_type())){ $output = sprintf( '%1$s <p class="read-more-container"><a class="read-more button" href="%2$s">View recording ...</a></p>', $excerpt, get_permalink() ); } elseif ( has_excerpt() ) { $output = sprintf( '%1$s <p class="read-more-container"><a class="read-more button" href="%2$s">Read more ...</a></p>', $excerpt, get_permalink() ); } return $output; }
June 28, 2020 at 1:43 pm #1344808LeoStaffCustomer SupportCan you open a new topic for your question as this one is a bit old with multiple authors already?
Thanks 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.