A fresh mix of code snippets and tutorials

WordPress: Customize Read More Links and Text

Here are two code snippets that are useful for customizing the “read more” link. The read more link is displayed on archive views like category archives, author archives, posts archives, search results, and so forth. You also will find the read more link displayed on the site’s homepage and on any page where posts excerpts are displayed.

The first code snippet filters the read more link output. Specifically the function below moves the read more link inside of the excerpt’s closing paragraph tag. The following code may be added to your site via theme functions or simple custom plugin.

function shapeSpace_excerpt_read_more_link($content) {
	if (is_singular() || !is_main_query()) return $content;
	$content = substr($content, 0, -5); // display link inside last closing </p>
	$link = ' <a class="more-link" href="'. esc_url(get_permalink(get_the_ID())) .'">Continue reading »</a>';
	return $content . $link;
add_filter('the_excerpt', 'shapeSpace_excerpt_read_more_link');

You can go in and tweak the markup details or anything else that you’d like. The snippet is simply a starting point to dialing in your own solution.

Customize the read more text

If you’re using the previous snippet (above), then you don’t really need this snippet. The following code simply changes the link text on the read more link. So by default, the link text says something like “read more”. If that is the only thing you want to change, you can add the following

function shapeSpace_content_read_more_link($more_link, $more_link_text) {
	return str_replace($more_link_text, 'Continue reading »', $more_link);
add_filter('the_content_more_link', 'shapeSpace_content_read_more_link', 10, 2);

The only thing to do here is change the link text, which currently is set to: Continue reading »

Have fun! :)

Learn more

Digging Into WordPressWordPress Themes In DepthWizard’s SQL Recipes for WordPress