作者头像
Zairun
60 分前 2026年02月22日 13:43

把这段代码添加到 functions.php 中,以前乱码添加代码后面,它会自动修复前台显示的标签云乱码。

方法二:后台手动修复(更直观)
如果不方便操作数据库,可以直接在WordPress后台手动修复:

进入后台 → 碎语 → 标签

在标签列表中,找到那些显示为 #247bff 样式的乱码标签

鼠标悬停在标签上,点击“编辑”

在编辑页面,把标签名称里的 & 手动改成 &

点击“更新”保存

/**
 * 修复碎语标签云中的HTML实体乱码
 */
function fix_micropost_tag_cloud($html) {
    // 只修复碎语标签云
    if (strpos($html, 'micropost_tag') !== false) {
        $html = str_replace('&', '&', $html);
        $html = preg_replace('/&(#[0-9]+)/', '$1', $html);
    }
    return $html;
}
add_filter('wp_tag_cloud', 'fix_micropost_tag_cloud');

/**
 * 修复碎语标签页面的乱码
 */
function fix_micropost_tag_title($term_title) {
    if (is_tax('micropost_tag')) {
        $term_title = html_entity_decode($term_title, ENT_QUOTES, 'UTF-8');
    }
    return $term_title;
}
add_filter('single_term_title', 'fix_micropost_tag_title');

 

话题 #247bff
评论 0 热度 38

发表评论

Valid RSS