How to Customize or Remove […] from WordPress Excerpts

Excerpt is a good way to shorten your article, it’s more like a summary of the article. Other than front page, some themes may use excerpts on the archive pages as well.The default WordPress excerpts are limited to first 55 words of the content and ends with ellipsis […] at the end of the paragraph.

To display an excerpt of the post, you may use <?php the_excerpt(); ?> in the loop. Please refer to WordPress Codex page for more info about this.

Customize […] in WordPress excerpts

If you’d like to change the […] in the excerpts to something more useful like Read More, you may use the code below. You may also want to change the text to other word. The text will be linked to the permalink of the post.

1 2 3 4 5 6 7 8 9 10 11 12
<?php
//* Customize [...] in WordPress excerpts
add_filter( 'the_excerpt', 'sp_read_more_custom_excerpt' );
function sp_read_more_custom_excerpt( $text ) {
if ( strpos( $text, '[…]') ) {
$excerpt = str_replace( '[…]', '<p><a class="more-link" href="' . get_permalink() . '">Read More →</a></p><br>', $text );
} else {
$excerpt = $text . '<p><a class="more-link" href="' . get_permalink() . '">Read More →</a></p>';
}
return $excerpt;
}
view raw custom-readmore-excerpt.php hosted with ❤ by GitHub

As you can see from the code above, I added the .more-link class so you can further customize the output of the Read More link.

Remove […] from WordPress excerpts

To remove […] from the excerpts, you may use the following code. The code should be in functions.php file of your child theme.

1 2 3 4 5 6 7 8
<?php
//* Remove [...] from WordPress excerpts
function afn_customize_excerpt_more( $more ) {
return ' ';
}
add_filter('excerpt_more', 'afn_customize_excerpt_more');
view raw functions.php hosted with ❤ by GitHub

If you’ve any question about the WordPress excerpts, feel free to leave your comment below.

Comments

  1. Tiyo Kamtiyono says

    Simple, and something that must to be understood, but I often don’t pay attention to this. What I don’t really understand is your first script on the sixth until tenth line, why is there an if-else?

    Thanks before :)

  2. Lily says

    This article was really helpful to me, thank you. (I was having a hard time trying to get change those ellipses.)

    But I do have a question. Is there a way to have just the 3 dots (without the brackets) after the excerpt AND the read more link underneath that?

    Because right now the excerpt gets cut off abruptly, and although there is the read more box underneath, it still looks a bit unfinished. (you can see that here: http://www.ashestobeauty.net/blog/) . So if it’s not too much trouble, how do I have both, but without the brackets?

    thank you!! :)

  3. Maksim says

    perfect post, everything works great!

    could you please help how to remove a space after excerpt?
    I changed […] to simple …
    removed tags in your code to hold it on one line, but still have a small issue.
    Example: “this is a last word in current line …”
    That space is killing me.
    Thank You!

Leave a Reply

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