垃圾站 WP教程 WordPress文章摘要末尾默认省略号如何修改成更多

WordPress文章摘要末尾默认省略号如何修改成更多

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

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

1、去掉方括号

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

2、修改为更多超链接

function theme_excerpt_more($more) {
    global $post;    
    return '<a href="'.get_permalink($post->ID).%20'" 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/

上一篇
下一篇
联系我们

联系我们

返回顶部