Wordpress自动设置第一段为摘要

我们要修改formatting.php文件,文件的路径为。当然了,每个人的www文件夹位置都不一样,找到自己网站文件夹下面的wp-include文件夹就好。

[root@localhost ~]# cd /data/www/default/wordpress/wp-includes/
[root@localhost wp-includes]# vim formatting.php 

找到wp_trim_excerpt不分。在vim里按ESC,后输入 

:/wp_trip_excerpt

再敲回车就搜索到这个部分了。

在这个函数结束后,再添加下面的代码

add_filter( 'wp_trim_excerpt', 'my_custom_excerpt', 10, 2 );
 
function my_custom_excerpt($text, $raw_excerpt) {
    if( ! $raw_excerpt ) {
        $content = apply_filters( 'the_content', get_the_content() );
        $text = substr( $content, 0, strpos( $content, '</p>' ) + 4 );
    }
    return $text;
}

最后保存文件退出就好了。

猜你喜欢

转载自www.cnblogs.com/panxk/p/12629750.html
今日推荐