Pages - Menu

Thursday, 12 February 2015

Excerpt limit with custom words without plug-ins

If you want to manage throughout the website:

unction custom_excerpt_length( $length ) {
return 28;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

 








 Or in each case:

in function.php:

<?php
function string_limit_words($string, $word_limit)
{
  $words = explode(' ', $string, ($word_limit + 1));
  if(count($words) > $word_limit)
  array_pop($words);
  return implode(' ', $words);
}
?>


Where you want to display the excerpt:

p><?php
  $excerpt = get_the_excerpt();
  echo string_limit_words($excerpt,25);
?></p>