Modifying the bracketed ellipsis [...] at the end of post excerpt

Last updated on February 13, 2010. Tags: ,

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 (…).

Changing the [...] into something else

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.

Few more tricks

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('[...]', '&hellip;', $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 tweaks

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • StumbleUpon
  • Technorati

Related Posts

You might also be interested (randomly generated):

Post Comments

Please double check your comment before clicking the "Post" button. Once you clicked it, there will be no way for you to edit your comment.





* Required. Your email will never be displayed in public.