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.

Published by

Tom

http://fulltimeninja.com/tom

2 thoughts on “Replacing the […] in WordPress”

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.