wordpress自定义摘要截取字数的代码

时间:2022-10-23 08:45:10
代码如下:

function excerpt($limit) { 
$excerpt = explode(' ', get_the_excerpt(), $limit); 
if (count($excerpt)>=$limit) { 
array_pop($excerpt); 
$excerpt = implode(" ",$excerpt).'...'; 
} else { 
$excerpt = implode(" ",$excerpt); 

$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt); 
return $excerpt;