How To: Remove ‘Continue Reading’ from Excerpts – WordPress

Advertisement

Woooah didn’t notice times flies by and this is my first post this year, 7 months without sharing new article can’t believe it, anyway this time I’d like to share removing ‘Continue Reading’ button on manually inputted excerpt, we have to talk few filters here and don’t worry it’s easy.

So let’s get started

Filter Reference

excerpt_more, this is used to filter auto generated excerpt, just in case you need to also, and

get_the_excerpt this contains the excerpt string and this is what we need.

Below is a simple Hook that would do the Job.


/*
 * Removed Continue reading on manually inputted excerpt;
 */
function rs_theme_custom_excerpt_more( $output ) {
	global $post;

	if ( has_excerpt() ) {
		$output .= '<p><a class="read-more" href="'. get_permalink( $post->ID ) .'">Read More</a></p>';
	}

	return preg_replace( '/<a [^>]+>Continue reading.*?< \/a>/i', '', $output );
}
add_filter( 'get_the_excerpt', 'rs_theme_custom_excerpt_more', 20 );
</a>

Let’s explain it piece by piece


if ( has_excerpt() ) {
/*....*/
}

I’ve added condition here to check whether the current post contain manually inputted excerpt then display our custom ‘read more’ or ‘continue reading’ button, you can remove or comment it out if you don’t need custom read more button, but just in case 😉


return preg_replace( '/<a [^>]+>Continue reading.*?< \/a >/i', '', $output );

This regex simply replaces ‘Continue reading.’ button to empty string, and this is what we only need.

Visit the_excerpt() for full reference.

Hope that helps, happy coding ^_^

Advertisement