Replacing the […] in WordPress

Some of you might be wondering what I mean by the […], well I am of course referring to the symbol generated by WordPress upon calling the function the_excerpt(). Now personally I really dislike the symbol which is generated as it often doesn’t fit with my design, and I always prefer to have an ellipse – … followed by a link to continue reading – but how on earth could we go about doing this? Does the answer lie in using jQuery to find and replace this horrendous symbol? Perhaps we need to add some arguments to the the_excerpt() function?

No, it’s far simpler than that.

All that needs to be done is the addition of some code to the functions.php file in your theme directory. So head over to this file (if it doesn’t exist, create it) and go to your next free line, and copy and paste the code from below.

function new_excerpt_more($post) {
	return '...</p><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading...' . '</a>';
add_filter('excerpt_more', 'new_excerpt_more');

So the above code replaces the default […] with something that looks like “… Continue Reading…”, where the continue reading text is a link to the article itself. You could replace this with whatever code you like and have bundles of fun if you like that kind of thing. Just remember to not leave any blank lines at the bottom of your functions.php file as this can cause errors later down the line.






2 responses to “Replacing the […] in WordPress”

  1. Arjun Vasudeva avatar

    Nice blog dude, keep it up!

    1. Tom avatar

      Thanks man, kind of you to say so!