How to filter a WordPress theme's 'more link' text

Changing the more link in a WordPress theme is easy. Just open your theme files and change it. But, if you’re writing a plugin to change this or want to preserve your theme’s code (e.g., child themes), you need a way to easily edit this.

I’ve seen some themes add their own more link filter hook, but this is unnecessary because WordPress 2.8 introduced the_content_more_link filter hook. Maybe this post will help those theme authors cut back on an extra filter hook when it’s not needed.

This will allow us to easily overwrite the default.

What is the more link?

When writing a WordPress post, you can cut the text off at any point by adding in this code:

<!--more-->

If you’re using a theme that shows the standard full post on the home/blog page of your site, this will cut the article short at the point you added the code. It will also add a link to the single-post view where the reader can continue reading the post.

Using the_content_more_link filter hook

What we want to do is change our theme’s more link text, but we need to do this the appropriate way, and the appropriate way means not hacking up your theme author’s code.

Let’s assume our theme’s more link outputs “(more…)” when we add the <!–more–> link within the post editor. Maybe we don’t like that message too much. We’d like to change it to read “Continue reading →” instead.

Open your theme’s (or child theme’s) functions.php file and paste this code in:

<?php

add_filter( 'the_content_more_link', 'my_more_link', 10, 2 );

function my_more_link( $more_link, $more_link_text ) {
	return str_replace( $more_link_text, 'Continue reading &rarr;', $more_link );
}

?>

That’s all there is to it. Enjoy your custom more link text.