All in One SEO 插件提取中文描述过短解决方法

All in One SEO(也叫AIOSEO)是WordPress中最流行的SEO插件之一,功能非常强大,使初学者和专家都能轻松地在他们的网站上优化SEO。但是All in One SEO Pack有一个小问题就是对中文文章内容页截取的描述过短。

       All in One SEO的文章描述长度跟WordPress的摘要长度一样,默认是55个字符,要怎么才能把摘要长度设置长一些呢?网上也有很多方法教程,但是我看了一下基本上是针对All in One SEO 4.0.0之前的版本的修改方案.

以下介绍一下针对4.0.0以上的版本修复方案:

1. 编辑文件:/wp-content/plugins/all-in-one-seo-pack/app/Common/Traits/Helpers/WpContext.php

2. 找到以下代码块

/**
* Returns the description based on the post content.
*
* @since 4.0.0
*
* @param  WP_Post|int $post The post (optional).
* @return string            The description.
*/
public function getDescriptionFromContent( $post = null ) {
$post = ( $post && is_object( $post ) ) ? $post : $post = $this->getPost( $post );

static $content = [];
if ( isset( $content[ $post->ID ] ) ) {
return $content[ $post->ID ];
}

if ( empty( $post->post_content ) || ! empty( $post->post_password ) ) {
$content[ $post->ID ] = '';

return $content[ $post->ID ];
}

$postContent          = $this->getPostContent( $post );
$postContent          = wp_trim_words( $postContent, 55, '' );
$postContent          = str_replace( ']]>', ']]>', $postContent );
$postContent          = preg_replace( '#(<figure.*\/figure>|<img.*\/>)#', '', $postContent );
$content[ $post->ID ] = trim( wp_strip_all_tags( strip_shortcodes( $postContent ) ) );

return $content[ $post->ID ];
}

把wp_trim_words( $postContent, 55, ” )中的55改成你要的长度,比如改成wp_trim_words( $postContent, 120, ” )

3. 以下是修改前和修改后的效果

修改前;

 修改后:

转载请注明出处:All in One SEO 插件提取中文描述过短解决方法 - 罗旭东

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值