If you use post excerpts instead of the entire content on your WordPress blog posts index page, and on archives pages, you may notice that your excerpts end with this: "[...]"
. You may also notice that it doesn’t link to the post.
WordPress automatically appends that bracket/ellipses to excerpts. Here I show you how to change the brackets and ellipsis, and instead replace it with your own custom “Read more” text. Also, the “Read more” text will link to the actual article.
The following code replaces the "[...]"
and lets you add custom “Read More” text for excerpts. There are 3 examples, below.
Example 1: ... Read more
The first example replaces the bracket and ellipses with an ellipses followed by a link to the post. The link text will be “Read more”. So, it will look like this:
... Read more
You can change “Read more” to your own custom text on line 7.
/** * Adds a custom "Read more" link to post excerpts. * Replaces "[...]" (appended to automatically generated excerpts) with "... Read more" and it links to the article. */ function isa_excerpt_read_more( $more ) { global $post; $anchor_text = 'Read more'; $more = ' … <a href="'. esc_url( get_permalink() ) . '">' . $anchor_text . '</a>'; return $more; } add_filter('excerpt_more', 'isa_excerpt_read_more');
Example 2: ... Read more -->
The second example is just like the one above, except that it adds an arrow to the “Read more” text. So, it will look like this:
... Read more -->
You can change “Read more” to your own custom text on line 7.
/** * Adds a custom "Read more" link to post excerpts. * Replaces "[...]" (appended to automatically generated excerpts) with "... Read more-->" and it links to the article. */ function isa_excerpt_read_more_arrow( $more ) { global $post; $anchor_text = 'Read more →'; $more = ' … <a href="'. esc_url( get_permalink() ) . '">' . $anchor_text . '</a>'; return $more; } add_filter('excerpt_more', 'isa_excerpt_read_more_arrow');
Example 3: (...more -->)
The third example replaces the bracket and ellipses with a link to the post. The link will be an ellipses followed by “more” and an arrow, and this will be wrapped in parenthesis. So, the link will look like this:
(...more -->)
You can change this to your own custom text on line 7.
Unlike the previous 2 examples, in this example, the ellipsis is part of the anchor text of link.
/** * Adds a custom "more" link to post excerpts. * Replaces "[...]" (appended to automatically generated excerpts) with "(...more-->)" and it links to the article. */ function isa_excerpt_more_link( $more ) { global $post; $anchor_text = '(…more →)'; $more = ' <a href="'. esc_url( get_permalink() ) . '">' . $anchor_text . '</a>'; return $more; } add_filter('excerpt_more', 'isa_excerpt_more_link');
Side Note
If you’re using the excerpt for the head meta description tag for single posts, then you’ll need to remove the HTML link from it. So, for the excerpt in the head meta description tag, be sure to strip the tags, like so:
$meta_description = strip_tags(get_the_excerpt());
Kia
March 17th, 2012 at 5:50 pm
Trying to get the first function to work, but nothing I do seems to make any difference.
I have a basic loop with…
<a href="”>
…and I’m still getting the default ‘(more…)’ text, any light you can shed on this would be great!
Isabel
March 18th, 2012 at 1:06 am
I just double-checked, the function works. Are you getting the text “more”? If yes, there must be another function in your theme setting that, because that’s not the default. The default is “[…]”, just the brackets and dots. Search your
functions.php
for one of these:'excerpt_more'
or'get_the_excerpt'
to see if there is another filter setting your “more…”.