- This topic has 11 replies, 3 voices, and was last updated 2 years, 2 months ago by Ying.
-
AuthorPosts
-
January 4, 2022 at 2:46 pm #2069317Lauren
Hi, I’d like to add a few classes to the read more button on the blog post excerpts on the blog feed page.
I’d like to add the classes “js-scroll” and “smc-button” to the paragraphic tag with the class “read-more-container”, and I’d like to add the class “button-wrap” to the link tag with the classes “read-more” and “button” – however, I can’t find that markup in the theme files.
Thanks!
January 4, 2022 at 3:16 pm #2069332YingStaffCustomer SupportHi Lauren,
Try this PHP snippet:
https://docs.generatepress.com/article/generate_content_more_link_output/#usageAdding PHP: https://docs.generatepress.com/article/adding-php/
January 5, 2022 at 8:39 am #2070158LaurenHi Ying,
I added this snippet to my functions.php file in my child theme, but I am not seeing the extra class appear on the blog feed page.
January 5, 2022 at 9:17 am #2070208DavidStaffCustomer SupportHi there,
can you share a link to the blog so we can take a look?
January 5, 2022 at 9:37 am #2070228LaurenSure: https://staging-skylineconsultingco.kinsta.cloud/marketing-insights/
I’m not sure if this matters, but the classes on the links on my site are “read-more” and “button” and not “read-more” and “content-read-more” like it is in the php snippet.
Thanks!
January 5, 2022 at 6:31 pm #2070609YingStaffCustomer SupportHi Lauren,
Try this one instead:
add_filter( 'generate_excerpt_more_output', 'lh_generate_blog_read_more_button' ); add_filter( 'generate_content_more_link_output', 'lh_generate_blog_read_more_button' ); function lh_generate_blog_read_more_button( $output ) { $settings = wp_parse_args( get_option( 'generate_blog_settings', array() ), generate_blog_get_defaults() ); if ( ! $settings[ 'read_more_button' ] ) { return $output; } return sprintf( '...%5$s<p class="read-more-container js-scroll smc-button"><a title="%1$s" class="read-more button button-wrap" href="%2$s">%3$s%4$s</a></p>', the_title_attribute( 'echo=0' ), esc_url( get_permalink( get_the_ID() ) . apply_filters( 'generate_more_jump','#more-' . get_the_ID() ) ), wp_kses_post( $settings['read_more'] ), '<span class="screen-reader-text">' . get_the_title() . '</span>', 'generate_excerpt_more_output' == current_filter() ? '' : '' ); }
January 10, 2022 at 10:58 am #2075749LaurenThat worked! Thank you Ying!
January 11, 2022 at 9:53 am #2076925YingStaffCustomer SupportNo problem π
February 7, 2022 at 12:07 pm #2108680LaurenHi Ying,
I think that after adding the code, the blog excerpts are no longer followed by an ellipsis (…) – is there a way to add that back in?
Thanks!
February 7, 2022 at 12:41 pm #2108720YingStaffCustomer SupportI’ve updated the code here π Try this one:
https://generatepress.com/forums/topic/customize-read-more-button-html/#post-2070609February 7, 2022 at 1:29 pm #2108763LaurenThat’s perfect! Thank you so much
February 7, 2022 at 1:33 pm #2108774YingStaffCustomer SupportYou are welcome π
-
AuthorPosts
- You must be logged in to reply to this topic.