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

  • 相关阅读:
    接口测试神器Apifox究竟有多香?
    NumPy数组基础
    Java--静态字段与静态方法
    基于Spring Boot的大学校园防疫与服务系统毕业设计源码111556
    【逆向专题】【危!!!刑】(一)使用c#+Win32Api实现进程注入到wechat
    Python数据分析实战-实现一维列表(数组)和多维列表(数组)的相互转化(附源码和实现效果)
    Java 图形用户界面设计——GUI编程
    jenkins使用 mvnd 加速maven 项目打包
    Lua __metatable键
    “热帖”统计
  • 原文地址:https://blog.csdn.net/rohsuton/article/details/125406685
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号