Always show “Read more” when using GeneratePress

If you have the problem, that some posts do not show the “Read more” link when using WordPress in combination with the GeneratePress theme, you can use the following code snippets to solve your problem.

The problem sometimes occur, when your full post contains some special tags, e.g. <pre> or <code>.

To solve the problem, you have to disable the default “Read more” link. This can be done by adding this code to your themes functions.php:

add_filter( 'excerpt_more', function ( $more ) {
	return '';
}, 21 );

After that, you have to add a new “Read more” link after every automatically generated excerpt. This can be done by adding this code:

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

	$output = sprintf(
		'%1$s ... <a class="read-more" href="%2$s" title="">%3$s</a>',
		$excerpt,
		get_permalink(),
		__( 'Read more', 'my_theme' )
	);

	return $output;
} );

Now, your archive pages should be fine and every post should show a “Read more” link.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top