By default, WordPress excerpt length is set to 55 words. Open you theme’s functions.php file and add the below code or you can also add the below code if you are using any site-specific plugin.
1 2 3 4 5 6 7 8 9 10 | /** * Filter the excerpt length to 20 words. * * @param int $length Excerpt length. * @return int (Maybe) modified excerpt length. */ function wpdocs_custom_excerpt_length( $length ) { return 20; } add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 ); |
Make the “read more” string link to the post:
Place this in a theme’s functions.php to make the “read more” link to the post
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /** * Filter the "read more" excerpt string link to the post. * * @param string $more "Read more" excerpt string. * @return string (Maybe) modified "read more" excerpt string. */ function wpdocs_excerpt_more( $more ) { if ( ! is_single() ) { $more = sprintf( '<a class="read-more" href="%1$s">%2$s</a>', get_permalink( get_the_ID() ), __( 'Read More', 'textdomain' ) ); } return $more; } add_filter( 'excerpt_more', 'wpdocs_excerpt_more' ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.