惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
量子位
T
Tailwind CSS Blog
T
Threatpost
The GitHub Blog
The GitHub Blog
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
P
Proofpoint News Feed
博客园 - 司徒正美
L
LangChain Blog
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
S
Secure Thoughts
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
H
Hacker News: Front Page
T
Troy Hunt's Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
T
Tor Project blog
T
The Blog of Author Tim Ferriss
I
Intezer
P
Privacy & Cybersecurity Law Blog
美团技术团队
N
Netflix TechBlog - Medium
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Last Week in AI
Last Week in AI

WordPress大学

WordPress 正确移除 Feed 输出的 wellformedweb.org/CommentAPI 恶意网址 – WordPress大学 修复 Yoast SEO 在多语言网站输出Schema首页为其他语言网址的问题 – WordPress大学 使用 Resend 服务为 WordPress 网站配置SMTP发送邮件 – WordPress大学 Cimo:一款在浏览器端压缩和转换为 WebP 图片的WordPress插件 – WordPress大学 All In One SEO 插件低于4.9.3版本存在 REST API 端点漏洞 – WordPress大学 FluentCart 微信支付网关插件:WPKJ Payment Gateway for FluentCart with WeChat – WordPress大学 FluentCart 支付宝付款网关插件:WPKJ Payment Gateway for FluentCart with Alipay – WordPress大学 FluentCart:优秀的WordPress商城插件,最有希望替代WooCommerce和EDD – WordPress大学 使用 Captcha for WordPress 拦截垃圾邮件/评论/表单提交 – WordPress大学 3 个 WordPress 文件管理插件存在安全漏洞,请尽快更新 – WordPress大学 如何修复 WordPress 错误:Non-existent changeset UUID – WordPress大学 什么是 LLMs.txt?它对SEO有用吗?WordPress 网站如何生成 LLMs.txt? – WordPress大学
正确禁止 WordPress 转义 title 标题中的分隔符破折号 – 和 & 符号 – WordPress大学
https://www.wpdaxue.com/user/auuAwtzuk · 2025-08-08 · via WordPress大学

当前位置:首页>WordPress建站>网站SEO>正确禁止 WordPress 转义 title 标题中的分隔符破折号 – 和 & 符号

默认情况下,WordPress 会将title标题中的 破折号 -& 等特殊符号进行转义,比如 - 转义为 –& 转义为 &。某些SEO人员说这个会引发SEO方面的问题,其实这个说法没有任何依据。但是,如果你真的很在乎这个所谓的问题,可以根据本文的教程解决。

禁止 WordPress 转义 title 标题中的破折号 - 和 & 号等特殊符号 - Decode Title Entities

一句话,为了安全。通过转义,可以避免某些情况下的恶意代码输出。当然,这种情况极少出现(我们也不知道如何恶意)。转义的代码结果在我们看来是不会对SEO产生不利影响的,否则WordPress官方开发团队也不会这样做。

不推荐的或无效的处理方法

不推荐的方法

网络上给出的解决方法大多数是直接全局禁用 wptexturize 功能这种做法是不推荐的!!因为在其他的一些场景中,通过转义增强安全性还是很有必要的。

add_filter('run_wptexturize', '__return_false');

失效的方法

似乎从 WordPress 4.4 开始,WordPress 就建议采用 add_theme_support( 'title-tag' );启用 document title 来输出标题,不再使用 wp_title() 函数直接输出标题。

所以,以下方法在现在的大部分主题中应该都不再生效了,除非你用的主题是老古董。

remove_filter('the_title', 'wptexturize');
remove_filter('wp_title', 'wptexturize');
remove_filter('single_post_title', 'wptexturize');

正确的禁止 title 转义的方法

现代 WordPress 主题基本采用 add_theme_support( 'title-tag' );启用 document title 来输出标题,在标题的输出函数 wp_get_document_title() 的最末端有一个过滤钩子 document_title,我们需要做的就是通过它来将转义后的内容反转义为正常输出,该方法不需要全局禁用 wptexturize,所做的影响仅限于标题输出。

完整的代码如下:

/**
 * 禁止 WordPress 转义 title 标题中的破折号 - 和 & 号等特殊符号
 * https://www.wpdaxue.com/disable-title-wptexturize.html
 */
function wpdx_decode_title_entities($title) {
    if (isset($title)) {
        $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
    }
    return $title;
}
add_filter('document_title', 'wpdx_decode_title_entities');

一般来说,将上面的代码添加到当前主题的 functions.php 或其他插件代码中即可。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

欢迎关注WordPress大学公众号 WPDAXUE

个人中心

购物车

优惠劵

今日签到

有新私信 私信列表

搜索

幸运之星正在降临...

点击领取今天的签到奖励!

恭喜!您今天获得了{{mission.data.mission.credit}}积分

  • 限制以下商品使用: 限制以下商品分类使用: 不限制使用:

    所有商品和商品类型均可使用