Wordpress - Custom Except Anywhere


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. }

URL: http://johnsardine.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.