在WordPress中,有內建顯示摘要的語法,但此語法若要有功能需搭配發文介面內的「文章摘要」才有效果,但現在你可以透過修改佈景主題以代換掉,讓發文不需要在該介面也可以使用這個函數,並且可自定義輸出文字的數量。
修改預設 the_excerpt()的長度
修改網站主程式檔案:/wp-includes/formatting.php
※注意:修改錯誤可能造成網站運作異常,主程式升級效果會被還原。
其中的「 $excerpt_length =140;」,140 可以代換您要顯示的字元數。
function wp_trim_excerpt($text) {
global $post;
if ( " == $text ) {
$text = get_the_content(");
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length =140;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, '[...]');
$text = implode(' ', $words);
}
}
return $text;
}


