Use the below example code in your theme’s functions.php file for WordPress custom excerpt length.
1 2 3 4 5 6 7 | function excerpt($num) { $limit = $num+1; $excerpt = explode(' ', get_the_excerpt(), $limit); array_pop($excerpt); $excerpt = implode(" ",$excerpt)."... (<a href='" .get_permalink($post->ID) ." '>Read more</a>)"; echo $excerpt; } |
Limit the length of the displayed excerpt by writing in the theme: excerpt(’20’); Example: This will limit the excerpt to 22 characters.
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.