WordPress函数:修改the_excerpt()函数摘要末尾默认省略号[…]为更多

追格官方小助手/ 2022年03月14日/ WordPress/ 浏览 1343

WordPress文章摘要末尾的“[…]”,怎么改成“…”或“更多”,我们可以通过WordPress的钩子excerpt_more来处理,看看追格小编是怎么操作的。


将下面代码放到当前WordPress主题functions.php文件内即可:


1、修改为:更多...

function theme_excerpt_more($more) {
    global $post;    
    return '<a href="'.get_permalink($post->ID). '" title="阅读全文">更多...</a>';
}
add_filter('excerpt_more', 'theme_excerpt_more');


2、去掉[ ],修改为:...

function theme_excerpt_more($more) {
    return '...';
}
add_filter('excerpt_more', 'theme_excerpt_more');


WordPress官方文档:https://developer.wordpress.org/reference/hooks/excerpt_more/

发表评论

暂无评论,抢个沙发...

客服 工单