1

I have posts with very different post lengths.

Sometimes there are very long posts, sometimes a very short comment on a book.

I have set my excerpt length to 50 words, but when a post is 25 words long, the "Read more" link doesn't show up.

Any ideas?

  • I had a same issue and solved it by changing code in the content.php (the template for the content). The code started with echo wp_trim_words( get_the_excerpt(),50, and I changed it by just using echo get_the_excerpt(), no trim no number ... to set a max amount words you then can use a function and your problem should be solved.(Or just except WP basic setting max. 55 words and you also do without an extra function) – Charles Jul 16 '15 at 2:51
1

The reason is the following check in the wp_trim_words() function:

if ( count( $words_array ) > $num_words ) {
    array_pop( $words_array );
    $text = implode( $sep, $words_array );
    $text = $text . $more;
} else {
    $text = implode( $sep, $words_array );
}

You can therefore try the following:

add_filter( 'wp_trim_words', function( $text, $num_words, $more ) {
    return $more === mb_substr( $text, -1 * mb_strlen( $more ) ) ? $text : $text . $more;
}, 11, 3 );

to append the $more link to the $text, if it's missing.

But I think your readers might be disappointent when they click the link on short posts and discover there's nothing new to read ;-)

| improve this answer | |
0

I use the Post Teaser plugin on my site. Just install and set how many words you want to show on the page; a link underneath opens the full post.

| improve this answer | |
-1

I had a similar problem and solved it by:

  • disabling the readmore link

    add_filter( 'the_content_more_link', 'modify_read_more_link' );
    function modify_read_more_link() {
      return '';
    }
    
  • adding the link in the template

echo '<a class="more-link" href="' . get_permalink() . '">Read more...';
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.