“Read more” link doesn’t show up when the post length is under the excerpt length

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 😉

Leave a Comment