WordPress自定义首页摘要字数和更多阅读链接

这是以前本站用到的,现在精简了,收藏在这里。

//摘要字数
function emtx_excerpt_length( $length ) {
return 150; //把150改为你需要的字数,具体就看你的模板怎么显示了。
}
add_filter( 'excerpt_length', 'emtx_excerpt_length' );

//去掉摘要后的[……]
function new_excerpt_more($more) {
return "";
}
add_filter('excerpt_more', 'new_excerpt_more');
//给查看全文加上链接
function emtx_continue_reading_link() {
 return ' <a href="'. get_permalink() . '" rel="nofollow">查看全文</a>';
}
function emtx_auto_excerpt_more( $more ) {
 return '......'.emtx_continue_reading_link();
}
add_filter( 'excerpt_more', 'emtx_auto_excerpt_more' );
 
function emtx_custom_excerpt_more( $output ) {
 if ( has_excerpt() && ! is_attachment() ) {
 $output .= emtx_continue_reading_link();
 }
 return $output;
}
add_filter( 'get_the_excerpt', 'emtx_custom_excerpt_more' );