I am Hack Sparrow
Captain of the Internets.

WordPress: How to customize the “Read More” link in Excerpt

Changing the Read More link in Excerpts

When you do the_excerpt(), WordPress ends the excerpt with a "[...]". Depending on your taste, you may or may not like the default more link in excerpts. I certainly don't like it, and here is what I used to change the Read More link in excerpts:

function custom_excerpt_more() {
    global $post;
    return '<a href="'. get_permalink($post->ID) . '">' . ' ... &raquo;' . '</a>';
}
add_filter('excerpt_more', 'custom_excerpt_more');

We hook in to the excerpt_more filter of WordPress and customize the link with our own link for the excerpt. Put whatever your more link in the excerpt should look like in the return value of the filter function.

Excercise

  1. What is the difference between filters and actions in WordPress?
  2. How do you use the_content() instead of the_excerpt() to create an excerpt?
  3. What does global do?

References
  1. excerpt_more
  2. the_excerpt
  3. WordPress Filters

Make a Comment