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

Last updated on November 28, 2011. 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:

  • No character symbol at the end of post excerpt
 $return = str_replace('[...]', '', $text);
  • Use HTML character entity reference (this one particular example shows real ellipsis)
 $return = str_replace('[...]', '&hellip;', $text);
  • End symbol touching the last character of post excerpt (notice the space before the open bracket?)
 $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

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

Related Posts

You might also be interested (randomly generated):

Post Comments





Comment Rules and Reminders

  • The links to the commentator's e-mail do not have nofollow tag. However, I will be very strict in approving comments.
  • When you comment, please say something that indicates that you indeed read my post. If your comment is a general statement that can fit to any blog post about any topic, it will be regarded as spam.
  • What you write in the name field may include keywords to your website provided that (1) it's only up to four words long and (2) at least one of these four words is your first name or nickname. I rather reply to Bob or to Joe Smith than to Online Marketing Tips.
  • 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.
  • Fields marked with asterisks (*) are required. Your email will never be displayed in public.