How can I create a “Read More” link using the_excerpt() on a static front page?

On the post edit page, if you fill Excerpt box with any text, the_excerpt() function doesn’t add read more link or ... at the end of the short description at frontend. Read more link is only included if Excerpt is set empty. This is not a bug, it’s a default behavior.

The solution is to avoid the excerpt_more filter to return read more link, and use the the_excerpt hook to add read more link.

// excerpt_more should be set the empty.
add_filter( 'excerpt_more', '__return_empty_string', 21 );

function wpse_134143_excerpt_more_link( $excerpt ) {
    $excerpt .= sprintf( 
            '... <a href="%s">%s</a>.',
            esc_url( get_permalink() ),
            __( 'continue reading' )
    );
    return $excerpt;
}
add_filter( 'the_excerpt', 'wpse_134143_excerpt_more_link', 21 );

Above code could go to your themes functions.php file.

Leave a Comment