Site logo

Archived topic

Read more-button disappears when using "manual" excerpts

7 replies · Started by Cecilia on January 21, 2018

Viewing posts 1–8 of 8

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 button

The automatic excerpt is fine, but for some posts I want to use the curated version that I have written for that blog post.

Hi 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 :)

Worked like clockwork! I just copied the code you sent into my child theme's functions.php, saved and - voilá!

Thank you!
<3

/Cecilia

You're welcome! :)

Hey 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
Joe

Hi 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;
}

Can you open a new topic for your question as this one is a bit old with multiple authors already?

Thanks :)

This archived topic is closed to new replies.