wordpress代码块中出现&quot,&gt等html转义字符解决方案

存在问题

后台编写代码块没有问题,但发布文章后出现html转义字符,如图

image-20250408224538953

在排除掉主题和插件影响后,发现是wordpress自动转义了

解决方案

来源:https://www.cnblogs.com/lmlblogs/p/17871572.html
进入wordpress仪表盘->外观->主题文件编辑器
找到functions.php
把下面代码添加到functions.php中

** 强制阻止WordPress代码转义
*http://www.bokequ.com/62.html
*/
function git_esc_html($content) {
    $regex = '/(<pres+[^>]*?classs*?=s*?[",'].*?prettyprint.*?[",'].*?>)(.*?)(</pre>)/sim';
    return preg_replace_callback($regex, 'git_esc_callback', $content);
}
function git_esc_callback($matches) {
    $tag_open = $matches[1];
    $content = $matches[2];
    $tag_close = $matches[3];
    $content = esc_html($content);
    return $tag_open . $content . $tag_close;
}
add_filter('the_content', 'git_esc_html', 2);
add_filter('comment_text', 'git_esc_html', 2);
add_filter('asgarosforum_filter_post_content', 'git_esc_html', 2);

image-20250408225014047

保存设置

解决后

需要手动更新每一篇文章才能生效

image-20250408225130784

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇