感谢@m0r7if3r对您的所有帮助。我不认为我能理解Regex的部分。这是我正在使用的代码,它可以工作:
function wp_strip_header_tags( $text ) {
$raw_excerpt = $text;
if ( \'\' == $text ) {
//Retrieve the post content.
$text = get_the_content(\'\');
//remove shortcode tags from the given content.
$text = strip_shortcodes( $text );
$text = apply_filters(\'the_content\', $text);
$text = str_replace(\']]>\', \']]>\', $text);
}
$regex = \'#(]*>)\\s?(.*)?\\s?()#\';
$text = preg_replace($regex,\'\', $text);
/***Change the excerpt word count.***/
$excerpt_word_count = 60; //WP default is 55
$excerpt_length = apply_filters(\'excerpt_length\', $excerpt_word_count);
/*** Change the excerpt ending.***/
$excerpt_end = \'[...]\'; //This is the WP default.
$excerpt_more = apply_filters(\'excerpt_more\', \' \' . $excerpt_end);
$excerpt = wp_trim_words( $text, $excerpt_length, $excerpt_more );
return apply_filters(\'wp_trim_excerpt\', $excerpt, $raw_excerpt);
}
add_filter( \'get_the_excerpt\', \'wp_strip_header_tags\', 5);