WordPress修改the_excerpt()函数摘要末尾默认省略号[…]
网站文章 2026-09-21 06:17:22 1 0

the_excerpt() 函数默认将 “[…]” 作为摘要末尾的更多内容字符显示,如果想更换为更多内容超链接,或者不想要方括号 “[]” 只显示省略号 “…”,可以通过 wordpress 钩子 excerpt_more 来修改,且很简单。

在主题的 functions.php 文件,添加下面函数即可

1、去掉方括号

1
2
3
4
function theme_excerpt_more($more) {
    return '...';
}
add_filter('excerpt_more', 'theme_excerpt_more');

2、修改为更多超链接

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

附:excerpt_more 钩子由 wp_trim_excerpt() 函数调用

文件位置:wp-includes/formatting.php

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

文章说明
本文标签:
©版权声明
本站提供的一切软件、教程和游戏辅助仅限用于娱乐和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络收集,版权争议与本站无关。如有侵权请邮件与我们联系处理。敬请谅解!6594404@qq.com