Site logo

Archived topic

How to display 'read more' when using the excerpt field

31 replies · Started by Dave Foy on March 21, 2017

Viewing posts 16–30 of 32

Having spent quite some time troubleshooting this (before finally searching here - duh!!!), it's good that there is an explanation.

However, given that this has come up before from a number of folks and has caused some confusion, is it reasonable to expect that the theme might handle this in a more robust/predictable way in a future release, to avoid others going down this same path?

Thank you.

Glad it helped!

I wish WP itself had a better way of handling this. I'll look into it some more and will come up with something solid enough for the theme :)

HI Tom,

I've absolutly no clue, where to put:

add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
function tu_excerpt_metabox_more( $excerpt ) {
$output = $excerpt;

if ( has_excerpt() ) {
$output = sprintf( '%1$s Read more',
$excerpt,
get_permalink()
);
}

return $output;
}

in order to get a "read more" - Button while using excerpt field in Blog view.

Hi
And for those ones who are looking for (like me), to have a button with the link text what has been set as the ‘Read more label’ in the Customiser :

add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
function tu_excerpt_metabox_more( $excerpt ) {
	$output = $excerpt;
    $settings = wp_parse_args( 
		get_option( 'generate_blog_settings', array() ), 
		generate_blog_get_defaults() 
	);
  
  
	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(),
			wp_kses_post( $settings['read_more'] )
		);
	}	
	return $output;
}

Awesome thanks for sharing!

Hi Leo,

Yes, I'm using a custom excerpt. I'm trying to mimic the way the Site Library's Classic theme centers "Read More" under the excerpt. In looking over the reference you posted, I see I need to add the p class called read-more-container to my Read More link snippet.

Thanks!

No problem!

It's just fantastic I could find help so easily here!
Thanks Tom.
GeneratePress and your support is just incredible fantastic!

When "Display read more as button" is checked the "read more" link is enclosed by a

<p class="read-more-container"</p>

How could I accomplish that this is rendered the same way here?

Sorry, it was up there and I overlooked it.

Glad you figured out!

seems like the classes for the button changed a bit? updated code that works for me(add to child's functions.php):

//fix read more button with manual excerpts field
add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
function tu_excerpt_metabox_more( $excerpt ) {
	$output = $excerpt;
        $settings = wp_parse_args( 
		get_option( 'generate_blog_settings', array() ), 
		generate_blog_get_defaults() 
	);
	if ( has_excerpt() ) {
		$output = sprintf( '%1$s <p class="read-more-container"><a class="read-more button" href="%2$s">%3$s</a></p>',
			$excerpt,
			get_permalink(),
                        wp_kses_post( $settings['read_more'] )
		);
	}
	return $output;
}
This archived topic is closed to new replies.