最新消息:

wordpress摘要函数the_excerpt()默认字数长度修改

wordpress admin 3601浏览 0评论

wordpress中不是用插件实现的文章摘要的某些主题有应用到函数the_excerpt(),但是现在遇到一个问题就是这个函数的默认长度让我觉得有些短。所以现在想办法修改这个函数控制的摘要长度,搜索了很多重要找到一个清晰明了的,简单正确的的修改路径的文章。

在wp-includes目录下找到formatting.php,里面有这样一个函数:

function wp_trim_excerpt($text = '') {
        $raw_excerpt = $text;
        if ( '' == $text ) {
                $text = get_the_content('');

                $text = strip_shortcodes( $text );

                $text = apply_filters('the_content', $text);
                $text = str_replace(']]>', ']]>', $text);
                $excerpt_length = apply_filters('excerpt_length', 180);
                $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
                $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
        }
        return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}

将 $excerpt_length = apply_filters(‘excerpt_length’, 180);   180 改为你需要截取的字数。

转载请注明:爱开源 » wordpress摘要函数the_excerpt()默认字数长度修改

您必须 登录 才能发表评论!