Wordpress Excerpt Dynamic Length


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



Copy this code and paste it in your HTML
  1. function ms_rp_excerpt($limit) {
  2. $excerpt = explode(' ', get_the_excerpt(), $limit);
  3. if (count($excerpt) >= $limit) {
  4. array_pop($excerpt);
  5. $excerpt = implode(' ', $excerpt).'...';
  6. }
  7. else {
  8. $excerpt = implode(' ', $excerpt);
  9. }
  10. $excerpt = preg_replace('`\[[^\]]*\]`', '', $excerpt);
  11. return $excerpt;
  12. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.