‘Read-more’ on all Excerpts in WordPress

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.

Automatically Shorten the Manual Excerpt

When you are building or modifying a wordpress theme, you have the choice of either using ‘the_content()’ to show the full article, or ‘the_excerpt()’ to show a shorter version.
By default, the latter limits the output to the first 55 words of the post, and automatcally strips formatting and images.
To make things more flexible, the editor also allows you to add a manual excerpt that will have preference before the automatically generated one.
There is no default limit to the length of this manual excerpt, which might break some carefully designed templates.

To apply the excerpt length limit to all excerpts, a modification of a core wordpress function ‘wp_trim_excerpt()’ would be needed.
However, changing core files is not a good idea, as the changes will be lost after each update.

Luckily, the same result can be achieved by using a fillter hook on ‘get_the_excerpt’; the code for it is added to functions.php of the theme.

(updated to utilize the filters ‘excert_length’ and ‘excerpt_more’ – aug 2010)

function wp_trim_all_excerpt($text) {
// Creates an excerpt if needed; and shortens the manual excerpt as well
global $post;
  $raw_excerpt = $text;
  if ( '' == $text ) {
    $text = get_the_content('');
    $text = strip_shortcodes( $text );
    $text = apply_filters('the_content', $text);
    $text = str_replace(']]>', ']]&gt;', $text);
  }

$text = strip_tags($text);
$excerpt_length = apply_filters('excerpt_length', 55);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); //since wp3.3
/*$words = explode(' ', $text, $excerpt_length + 1);
  if (count($words)> $excerpt_length) {
    array_pop($words);
    $text = implode(' ', $words);
    $text = $text . $excerpt_more;
  } else {
    $text = implode(' ', $words);
  }
return $text;*/
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); //since wp3.3
}

remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'wp_trim_all_excerpt');

edit: expanded to take remove shortcode from the excerpt; 12/07/2010
edit: adapted to wp3.3; 16.01.2012

thanks to michael.oeser for his well written article: Wie man WordPress Textauszüge mit the_excerpt individuell anpasst. It contains even more details on how to tweak the excerpt.