Posted By

johnsardine on 03/11/11


Tagged

wordpress limit custom excerpt


Versions (?)

Wordpress - Custom Except Anywhere


 / Published in: PHP
 

URL: http://johnsardine.com

I did not created this, a friend provided it to me, and it seems really usefull so i thought i should share.

Usage: Paste that code in your functions .php and in your theme you put <?php> where 20 is the number of words you want

  1. //Excerpt - usage - < ?php echo excerpt(15); ? > - remove the spaces between the < and ?
  2. function excerpt($limit) {
  3. $excerpt = explode(' ', get_the_excerpt(), $limit);
  4. if (count($excerpt)>=$limit) {
  5. array_pop($excerpt);
  6. $excerpt = implode(" ",$excerpt).'...';
  7. } else {
  8. $excerpt = implode(" ",$excerpt);
  9. }
  10. $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
  11. return $excerpt;
  12. }

Report this snippet  

You need to login to post a comment.