Skip to content

Instantly share code, notes, and snippets.

@rfvcorreia
Created August 16, 2013 09:56
Show Gist options
  • Select an option

  • Save rfvcorreia/6248642 to your computer and use it in GitHub Desktop.

Select an option

Save rfvcorreia/6248642 to your computer and use it in GitHub Desktop.
Remove Shortcodes from excerpt
function custom_excerpt($text = '') {
$raw_excerpt = $text;
if ( '' == $text ) {
$text = get_the_content('');
$text = strip_shortcodes( $text );
$excerpt_length = apply_filters('excerpt_length', 50);
$excerpt_more = apply_filters('excerpt_more', ' ' . '...');
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
}
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}
remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
add_filter( 'get_the_excerpt', 'custom_excerpt' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment