存在问题
后台编写代码块没有问题,但发布文章后出现html转义字符,如图
在排除掉主题和插件影响后,发现是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);
保存设置
解决后
需要手动更新每一篇文章才能生效