Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Limit the number of words in excerpt without plugins
- Excerpt by default display a numbers of characters so some times brake a word, No you can set limit the number of words displayed in the excerpt without any plugin.
- Put the following code in your templates functions.php file.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- function royal_string_limit_words($string, $word_limit)
- {
- $words = explode(' ', $string, ($word_limit + 1));
- if(count($words) > $word_limit)
- array_pop($words);
- return implode(' ', $words);
- }
- Now put the following code in your template where you want to display the excerpt.
- 1
- 2
- 3
- 4
- <?php
- $excerpt = get_the_excerpt();
- echo royal_string_limit_words($excerpt,55);
- ?>
- Where 55 is the number of words (not character) to display.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement