您可能会尝试一些东西,我在几年前发现了这个解决方案,它工作得很好-它不仅允许覆盖字数限制,还允许一些基本样式,以便如果您的摘录包含粗体字,那么这些字将显示在摘录中。
// Improves the look of the excerpt, more words, allows bolding
function improved_trim_excerpt($text) {
$raw_excerpt = $text;
$excerpt_more = \'…<a class="more-link" href="\'. esc_url( get_permalink() ) . \'" title="\' . esc_html__( \'Continue reading\', \'wp-answers\' ) . \' ‘\' . get_the_title() . \'’">\' . wp_kses( __( \'Continue reading <span class="meta-nav">→</span>\', \'wp-answers\' ), array( \'span\' => array(
\'class\' => array() ) ) ) . \'</a>\';
if ( \'\' == $text ) {
$text = get_the_content(\'\');
$text = strip_shortcodes( $text );
$text = apply_filters(\'the_content\', $text);
$text = str_replace(\'\\]\\]\\>\', \']]>\', $text);
$text = strip_tags($text, \'<b><strong><del><em>\');
$excerpt_length = apply_filters(\'excerpt_length\', 55);//change 55 to whatever word limit you want
$newexcerpt_more = apply_filters(\'excerpt_more\', \' \' . $excerpt_more);
$words = preg_split("/[\\n\\r\\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
if ( count($words) > $excerpt_length ) {
array_pop($words);
$text = implode(\' \', $words);
$text = $text . $newexcerpt_more;
$text = force_balance_tags( $text );
} else {
$text = implode(\' \', $words);
$text = force_balance_tags( $text );
}
}
return $text;
}
remove_filter(\'get_the_excerpt\', \'wp_trim_excerpt\');
add_filter(\'get_the_excerpt\', \'improved_trim_excerpt\');
这将包含在你(希望是孩子)的主题函数中。php文件或自定义插件文件。。。。。