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

本文介绍了如何修复AllinOneSEO插件在4.0.0以上版本中对中文文章描述过短的问题。通过编辑/wp-content/plugins/all-in-one-seo-pack/app/Common/Traits/Helpers/WpContext.php文件,将默认的55个字符长度改为所需的长度,例如120个字符,从而增加摘要的长度。修改前后效果对比显示了调整后的描述更完整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 插件提取中文描述过短解决方法 - 罗旭东

你听说过Platinum SEO Pack这款插件没,这个插件包含了All in One SEO的所有功能,而且,和All in One SEO插件相比,它还具有更多的功能,该插件的主要功能: •针对搜索引擎优化页面和文章标题 •自动生成SEO相关的元标记(META Tags) •帮助你避免重复内容(为了防止被搜索引擎惩罚?) •让你为每篇文章全局编辑META说明和关键词 •与大部分其他插件兼容比如Auto Meta, Ultimate Tag Warrior等.当然你可能要停用All in One SEO pack •别怕改变永久链接(permalinks)了,这个插件提供了自动301重定向功能,这个功能是ALL in One SEO pack里没有的。 •可以对每篇文章设置index, noindex, follow or nofollow, noarchive, nosnippet, noodp, noydir 等元标记 •增加了一些可添加noindex标记的页面:类别页面、存档页面、tag页面、评论feed、rss feed、搜索结果页面等等。 •为首页的外部链接添加NOfollow属性 Platinum SEO Pack插件安装: 1.下载Platinum SEO PackL插件,然后上传插件到/wp-content/plugins/下的文件夹。 2.到wp管理后台插件页面,点击”Platinum SEO插件“激活插件,激活后插件后,在后台"Setting"--->"Platinum SEO",你会看到如下页面: 上面介绍的相关信息,都可以再页面中进行设置,Platinum SEO可以完全替换掉All In One SEO,改变永久链接形式时, 可以把旧地址用 301 跳转至新地址等新添加的功能,都给Platinum SEO插件添色不少,它也被很多人称为All-in-one-SEO-Pack插件的接班人,无论是否像它们说的那么神奇、强大,也只有你亲身体会了之后才会知道。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值