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.
[code]
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);
}
[/code]

Now put the following code in your template where you want to display the excerpt.
[code]
<?php
$excerpt = get_the_excerpt();
echo royal_string_limit_words($excerpt,55);
?>
[/code]
Where 55 is the number of words (not character) to display.

Leave a Reply

×

Your Cart

No products in the cart.
Start shopping

About Us

Royal Technologies is a System Integration house that supports Web Design, Web Hosting, Domain Registration, Search Engine Optimizing, IT Consulting, Remote or Telephone Support and Software Development. In simpler terms it’s an IT Company dealing in various aspects of implementation and maintenance of computerization. We have learnt from experience and have molded ourselves to be complete IT Company.

CONTACT US

Location

Copyright © 2008-2024 Royal Technologies. All rights reserved.
Development by Royal Technologies