码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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 插件提取中文描述过短解决方法 - 罗旭东

  • 相关阅读:
    做库存功能业务场景详解,S2B2B系统助力建筑建材企业精准掌握库存动态
    paddledet 训练旋转目标检测 ppyoloe-r 训练自己的数据集
    牛客网:NC41 最长无重复子数组
    生成对抗网络gan loss曲线图
    Linux指令——crontab
    【SpringCloud】微服务技术栈入门2 - Nacos框架与Feign
    中间件 | Redis - [安装 & 基本信息]
    【解决方案】MySQL 百万数据迁移到 ElasticSearch 的思考
    BUUCTF-WEB-刷题记录
    JAVA计算机毕业设计医疗病历交互系统Mybatis+系统+数据库+调试部署
  • 原文地址:https://blog.csdn.net/rohsuton/article/details/125406685
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号