Created
November 6, 2012 13:54
-
-
Save WebEndevSnippets/4024867 to your computer and use it in GitHub Desktop.
WordPress: Limit Length of All Excerpts (Manual and Automatic)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
remove_filter( 'get_the_excerpt', 'we_trim_excerpt' ); | |
add_filter( 'get_the_excerpt', 'we_trim_all_excerpt' ); | |
/** | |
* Limit Length of All Excerpts (Manual and Automatic) | |
* | |
*/ | |
function we_trim_all_excerpt($text) { | |
// Creates an excerpt if needed; and shortens the manual excerpt as well | |
global $post; | |
$raw_excerpt = $text; | |
if ( '' == $text ) { | |
$text = get_the_content(''); | |
$text = strip_shortcodes( $text ); | |
$text = apply_filters( 'the_content', $text ); | |
$text = str_replace( ']]>', ']]>', $text ); | |
} | |
$text = strip_tags($text); | |
$excerpt_length = apply_filters( 'excerpt_length', 45 ); | |
$excerpt_more = apply_filters( 'excerpt_more', ' ' . ' <a class="more-link" href="'.get_permalink().'">[More…]</a>' ); | |
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); | |
return apply_filters( 'wp_trim_excerpt', $text, $raw_excerpt ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment