36 | ‘Read-more’ on all Excerpts in WordPress

g+

Occasionally, the excerpt does not show a read-more at the end of the text. This is obviously the case, if the text content of the post is shorter than the set excerpt length.

Normally this is no problem – however, if your post contains images and/or important formatting, you would like to point the reader to the full post.

The above also assumes that you have customized your theme, to show a link to the post at the end of the excerpt – refer to the Codex chapter ‘Make the read-more link to the post‘.

A way to remedy the situation, is to edit functions.php of the theme, and to find the related code, such as:

function new_excerpt_more($more) {        global $post; 	return '<a href="'. get_permalink($post->ID) . '">' . 'Read the Rest...' . '</a>'; } add_filter('excerpt_more', 'new_excerpt_more');

Remove that, and add a new filter function in its place; something like:

function excerpt_read_more_link($output) {
 global $post;
 return $output . '<a href="'. get_permalink($post->ID) . '">Read All ...</a>';
}
add_filter('the_excerpt', 'excerpt_read_more_link');

And now you have a ‘read-more’ link at the end of each excerpt, linked to the full post.

This entry was posted in Tips & Tricks, WordPress and tagged , , , . Bookmark the permalink.

12 Responses to ‘Read-more’ on all Excerpts in WordPress

  1. Neil Gee (@neilgee01) comments:

    Thanks! – finding a solution took a while -but worth it!

  2. Eric comments:

    Thanks for this code but one question. How do I remove the [...] that is appearing before the “read more” link. I’d rather not have both [...] and read more in the excerpt.

    Thanks!

  3. Eberhard Auriga comments:

    Hi alchymyth,

    your solution “‘Read More’ to appear inline at the end of the excerpt” … works fine … Thanks …
    Do you know, whats the code to make “Read All …” translatable? I need the solution for a multilingual page …
    Thanks for your help in advance

    Greats from Berlin / Germany
    Hardy

    • michael replies:

      versuch es mit:

      return $output . '<a href="'. get_permalink($post->ID) . '">'. __('Read All ...','yourthemename') . '</a>';

      http://wpml.org/2009/05/wordpress-theme-localization/

      viele gruesse aus Bristol,
      Michael

    • Eberhard Auriga replies:

      Hi Michael,

      danke für den Hinweis … dein Code erzeugte wieder einen neuen Absatz …
      This code did the trick …
      return substr($output,0,-5).'<a href="'. get_permalink($post->ID) . '">'. __(' ... <strong>Continue reading <span class="meta-nav">&rarr;</span></strong>','twentyeleven') . '</a>';

      Danke
      Eberhard

  4. Jason Paul comments:

    Hi, Great solution. This has kind of been driving me crazy. Do you know of a way to get the ‘Read More’ to appear inline at the end of the excerpt as opposed to on it’s own paragraph line?

    • alchymyth replies:

      these together might work:
      function new_excerpt_more($more) {
      return ' ... ';
      }
      add_filter('excerpt_more', 'new_excerpt_more');

      function excerpt_read_more_link($output) {
      global $post;
      return substr($output,0,-5).'<a href="'. get_permalink($post->ID) . '"> Read All ...</a></p>';
      }
      add_filter('the_excerpt', 'excerpt_read_more_link');

      is a bit of a hack and not widely tested.

  5. Sven comments:

    Hi

    I have searched a few days to find a way to limit the lenght of each comment when they show up in my feed (rss).

    Is there a way to do this without changig WPs “core files” (or do I have to use php and change the feed.php)?

  6. Pingback: Tweets that mention ‘Read-more’ on all Excerpts in WordPress | TransformationPowerTools | for personal growth and transformation -- Topsy.com

    g+

    01/11/2010 | [...] This post was mentioned on Twitter by Daily Choices and Xavier Tolling, Mark Sumpter. Mark Sumpter said: 'Read-more' on …

Leave a Reply

Your email address will not be published.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>