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

https://srd.wordpress.org/plugins/advanced-excerpt/

Features:

  1. Keeps HTML markup in the excerpt (and you get to choose which tags are included)
  2. Trims the excerpt to a given length using either character count or word count
  3. Only the 'real' text is counted (HTML is ignored but kept)
  4. Customizes the excerpt length and the ellipsis character that are used
  5. Completes the last word or sentence in an excerpt (no weird cuts)
  6. Adds a read-more link to the text
  7. Ignores custom excerpts and use the generated one instead
  8. Theme developers can use the_advanced_excerpt() for even more control (see the FAQ)