You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

更换主题后WordPress经典编辑器变化,需在functions.php添加什么代码?

解决WordPress更换主题后经典编辑器变化的代码方案

更换主题后经典编辑器出现样式错乱、工具栏按钮缺失或自动切换为块编辑器等问题,通常是新主题未适配经典编辑器的默认配置导致的,以下是针对性的解决代码:

恢复经典编辑器默认样式

若编辑器排版、按钮样式异常,添加代码恢复WordPress原生编辑器样式:

// 恢复经典编辑器默认样式
add_action('admin_head', 'restore_classic_editor_styles');
function restore_classic_editor_styles() {
    if (is_admin() && (isset($_GET['post']) || (isset($_GET['post_type']) && $_GET['post_type'] !== 'attachment'))) {
        wp_enqueue_style('editor-buttons');
        add_editor_style();
    }
}

恢复完整编辑器工具栏

若工具栏按钮丢失,用代码重置为默认完整工具栏配置:

// 恢复经典编辑器完整工具栏
add_filter('tiny_mce_before_init', 'restore_full_classic_editor_toolbar');
function restore_full_classic_editor_toolbar($settings) {
    $settings['toolbar1'] = 'bold,italic,strikethrough,bullist,numlist,blockquote,alignleft,aligncenter,alignright,link,unlink,wp_more,spellchecker,fullscreen,wp_adv';
    $settings['toolbar2'] = 'formatselect,underline,alignjustify,forecolor,pastetext,pasteword,removeformat,charmap,outdent,indent,undo,redo,wp_help';
    return $settings;
}

强制启用经典编辑器(禁用块编辑器)

若新主题默认切换为Gutenberg块编辑器,添加代码强制保留经典编辑器:

// 强制启用经典编辑器,禁用块编辑器
add_filter('use_block_editor_for_post', '__return_false', 10);
add_filter('use_block_editor_for_post_type', '__return_false', 10);

使用说明

将对应代码添加到当前主题的functions.php文件末尾即可,操作前建议备份该文件,避免代码错误导致网站异常。

内容的提问来源于stack exchange,提问作者Mohamed El-Azzawy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 11:15:36