/ Published in: PHP

function that creates a template tag that can be used to insert excerpts with different lengths. Also controls characters that come after excerpt
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// In Functions.php: function the_excerpt_max_charlength($charlength) { $excerpt = get_the_excerpt(); $charlength++; if(strlen($excerpt)>$charlength) { $subex = substr($excerpt,0,$charlength-5); $exwords = explode(" ",$subex); $excut = -(strlen($exwords[count($exwords)-1])); if($excut<0) { echo substr($subex,0,$excut); } else { echo $subex; } echo "[...]"; } else { echo $excerpt; } } // In wordpress template: <?php the_excerpt_max_charlength(250); ?>
URL: http://codex.wordpress.org/Function_Reference/get_the_excerpt
Comments
