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

乐清SEO_开发应用_wordpress_ 乐清SEO2021-01-19 转载自:
代码如下:

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;