Last updated on November 28, 2011. Tags: functions.php, post excerpt
Aside from displaying the first 55 words of the content, another default configuration of WordPress post excerpt when the Excerpt form is left blank is that it will end with ellipsis enclosed by a square bracket ([...]).
Although the thing between the square brackets looks like an ellipsis, it's not really an ellipsis, just three periods in a row. You can verify this by highlighting the text, you will see that you can highlight only one or two periods indicating that they are separate characters. A real ellipsis (…) can only be highlighted as one unit and can be inserted using HTML code (…).
To change the end of the post excerpt into some other symbol (or group of symbols), insert the following codes in the Template Functions (functions.php) of you theme. As usual, the safest place to insert it if you're not sure is right after the first <?php or right before the last ?>.
function replace_ellipsis($text) {
$return = str_replace('[...]', '-', $text);
return $return;
}
add_filter('get_the_excerpt', 'replace_ellipsis');
In this particular example, the bracketed ellipsis was replaced by a hypen (-). Just replace the hypen with the character(s) that you want.
Below are some of the few tweaks that we can do by altering the second line of code only a little:
$return = str_replace('[...]', '', $text);
$return = str_replace('[...]', '…', $text);
$return = str_replace(' [...]', '-', $text);
I tested this tweak on WordPress 2.6.1 and WordPress 2.9.1. It will most likely work in any nearby version and all the versions in between them.
Posted by Greten on January 31, 2010 under WordPress
Comment Rules and Reminders