Wordpress - How to control manual excerpt length?

Take a look on my answer here: Best Collection of Code for your functions.php file

If I understood your question correctly, it does what you are looking for.

Place this in functions.php:

function excerpt($num) {
    $limit = $num+1;
    $excerpt = explode(' ', get_the_excerpt(), $limit);
    array_pop($excerpt);
    $excerpt = implode(" ",$excerpt)."... (<a href='" .get_permalink($post->ID) ." '>Read more</a>)";
    echo $excerpt;
}

Then, in your theme, use the code <?php excerpt('22'); ?> to limit the excerpt to 22 characters.

:)


With the recent version of Wordpress (v.3.3.0+), you can actually use wp_trim_words.

function excerpt($limit) {
    return wp_trim_words(get_the_excerpt(), $limit);
}

See also: https://stackoverflow.com/a/17177847/851045

Tags:

Excerpt