function improved_trim_excerpt( $text ) { if ( '' == $text ) { $permalink = get_permalink(); // my addition $text = get_the_content( '' ); $text = strip_shortcodes( $text ); $text = apply_filters( 'the_content', $text ); $text = preg_replace( '@<script[^>]*?> . *?</script>@si', '', $text ); $text = str_replace( ']]>', ']]>', $text ); $text = strip_tags( $text, '<b><em><i><p><strong><sub><sup><a>' ); // allowed tags (change as needed) $excerpt_length = apply_filters( 'excerpt_length', 20 ); $excerpt_more = apply_filters('excerpt_more', ' ' . ''); // my addition $words = explode( ' ', $text, $excerpt_length + 1 ); if ( count( $words ) > $excerpt_length ) { array_pop( $words ); array_push($words, '... <a class="more" href="'. get_permalink() . '">MORE»</a>'); $text = implode( ' ', $words ); $text = $text . $excerpt_more; $text = force_balance_tags( $text ); // my addition } } return $text; } remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' ); add_filter( 'get_the_excerpt', 'improved_trim_excerpt' );