Site logo

Archived topic

customize read more button HTML

11 replies · Started by Lauren on January 4, 2022

Viewing posts 1–12 of 12

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!

Hi 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.

Hi there,

can you share a link to the blog so we can take a look?

Hi 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() ? '' : ''
	);
}

That worked! Thank you Ying!

No problem :)

Hi 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!

That's perfect! Thank you so much

You are welcome :)

This archived topic is closed to new replies.