- This topic has 13 replies, 3 voices, and was last updated 4 years, 10 months ago by
Ying.
-
AuthorPosts
-
July 14, 2021 at 12:20 pm #1855906
Michael
I’m using manual excerpts and the Read more button was not appearing in the archives.
I added the Code Snippets plugin and used the Read More PHP from this article: https://docs.generatepress.com/article/activating-read-custom-excerpt/
Unfortunately, the Read more block now shows up on all pages with custom excerpts, not just the archives. This page demonstrates the issue: https://staging-studentloansherpa.kinsta.cloud/public-service-student-loan-forgiveness-basics-fine-print/
Is there a way to address this issue?
July 14, 2021 at 1:44 pm #1855964Ying
StaffCustomer SupportHi Michael,
Do you mean this read more button?
https://www.screencast.com/t/Z3rssapg4ZNiLet me know 🙂
July 14, 2021 at 2:11 pm #1855985Michael
That is the one!
If we could get rid of that, I’d be thrilled.
Thanks
July 14, 2021 at 2:26 pm #1855995Ying
StaffCustomer SupportTry this PHP snippet instead:
add_action( 'generate_after_entry_content', 'tu_static_read_more_button' ); function tu_static_read_more_button() { ?> <?php if ( is_home() || is_archive() ) : ?> <p class="read-more-container"> <a href="<?php the_permalink(); ?>" class="button">Read more</a> </p> <?php endif; ?> <?php }Let me know 🙂
July 14, 2021 at 6:17 pm #1856125Michael
Good news and bad news.
The original problem is fixed, but a new one was created.
The read more block looks good for posts with a custom excerpt, and the posts look correct. However, the posts on archive pages that do not have a custom excerpt now have two read more buttons.
Example: https://staging-studentloansherpa.kinsta.cloud/category/repayment/
Also, the read more button now comes immediately after the except text. I’d like to add a bit of space if possible.
Thanks again for the help.
July 14, 2021 at 7:49 pm #1856169Elvin
StaffCustomer SupportHi Michael,
If you must apply the code coming from this documentation – https://docs.generatepress.com/article/activating-read-custom-excerpt/ – only on archive pages, you can add a condition for it.
Say for example:
add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' ); function tu_excerpt_metabox_more( $excerpt ) { $output = $excerpt; if ( has_excerpt() ) { if(is_archive() || is_home()) { $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; }You can try replacing Ying’s code with this.
July 14, 2021 at 7:53 pm #1856174Michael
that code did not work for me.
I got this warning:
Don’t Panic
The code snippet you are trying to save produced a fatal error on line 15:
Unclosed ‘{‘ on line 2
July 14, 2021 at 9:13 pm #1856207Elvin
StaffCustomer SupportCan you screenshot the code added?
That error means there’s a missing
}.Perhaps the last
}on the bottom of the code (underreturn $output;) wasn’t copied? 😀July 15, 2021 at 11:27 am #1857224Michael
That is quite embarrassing.
Your code worked perfectly… the only flaw was my ability to copy and paste.
Thank you for the help. I got started with generatepress a couple of weeks ago and could not be more thrilled with everything. The site is incredibly fast, looks great, and has been easy to set up. I really appreciate it.
July 15, 2021 at 11:54 pm #1857634Elvin
StaffCustomer SupportThat happens to me from time to time as well. lol.
No problem. Glad you got it sorted. 😀
July 17, 2021 at 11:27 am #1859290Michael
I think I need to revive this discussion.
I noticed that the read more buttons are also missing in search results. Is there a way to fix this?
July 17, 2021 at 12:14 pm #1859315Ying
StaffCustomer SupportHi Micheal,
We can add search result page into the PHP snippet as well, try this:
add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' ); function tu_excerpt_metabox_more( $excerpt ) { $output = $excerpt; if ( has_excerpt() ) { if(is_archive() || is_home() || is_search() ) { $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; }July 17, 2021 at 12:21 pm #1859323Michael
Nailed it!
Thank you so much for the quick and helpful response!
July 17, 2021 at 12:33 pm #1859342Ying
StaffCustomer SupportYou are welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.