Function — Excerpt - martindubenet/Wordpress GitHub Wiki
Take control of the post excerpt
functions.php
Setting the post excerpt length
Sets the desired quantity of words (NOT characters) within
the_excerpt()
.
// Set the post excerpt length
function myTheme_excerpt_wordcount( $length ) {
return 20; // 20 words = ~130 characters
}
add_filter( 'excerpt_length', 'myTheme_excerpt_wordcount' );
Enable excerpt (textarea) for pages
function myTheme_theme_setup {
add_post_type_support( 'page', 'excerpt' );
}
add_action( 'after_setup_theme', 'myTheme_theme_setup' );
Plugins
The Advance Excerpt plugin
Features:
- Keeps HTML markup in the excerpt (and you get to choose which tags are included)
- Trims the excerpt to a given length using either character count or word count
- Only the 'real' text is counted (HTML is ignored but kept)
- Customizes the excerpt length and the ellipsis character that are used
- Completes the last word or sentence in an excerpt (no weird cuts)
- Adds a read-more link to the text
- Ignores custom excerpts and use the generated one instead
- Theme developers can use the_advanced_excerpt() for even more control (see the FAQ)