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

扩展ET_Builder_Module的自定义Divi模块字段在编辑器中异常

Divi自定义模块字段显示异常排查思路

针对你遇到的模块字段显示异常、按钮标签未填充问题,结合Divi开发的隐性规则,给出以下排查方向:

  • 验证翻译域注册状态
    所有esc_html__()调用使用的foo_translation必须已正确注册,否则文本无法被解析,导致按钮标签为空。在插件主文件或主题functions.php中添加注册代码:

    // 插件环境
    add_action('plugins_loaded', function() {
        load_plugin_textdomain('foo_translation', false, dirname(plugin_basename(__FILE__)) . '/languages/');
    });
    // 主题环境
    add_action('after_setup_theme', function() {
        load_theme_textdomain('foo_translation', get_template_directory() . '/languages/');
    });
    
  • 补充字段默认值
    Divi部分字段类型(如yes_no_button)依赖default参数才能正常渲染,即使是可选字段也建议添加。示例:

    'use_featured_images' => array(
        'label'           => esc_html__( 'Use Featured Images?', 'foo_translation' ),
        'type'            => 'yes_no_button',
        'options'         => array(
            'no' => esc_html__( 'No', 'foo_translation' ),
            'yes' => esc_html__( 'Yes', 'foo_translation' ),
        ),
        'default'         => 'no', // 新增默认值
        'option_category' => 'basic_option',
        'description'     => esc_html__( 'Would you like to use the featured images in the background of the category cards.', 'foo_translation' ),
        'toggle_slug'     => 'main_content',
    ),
    
  • 调整VB支持设置
    即使设置vb_support = 'off',部分Divi版本仍可能存在兼容性问题。尝试临时注释该属性,或切换为'partial'测试:

    // public $vb_support = 'off';
    public $vb_support = 'partial';
    
  • 确保模块注册时机正确
    Divi模块必须在Builder初始化完成后注册,否则字段结构无法被正确识别。修改实例化代码:

    add_action('et_builder_ready', function() {
        new CategoryGrid;
    });
    
  • 替换字段类型测试
    若当前Divi版本不支持yes_no_button类型,临时替换为select类型验证是否能正常显示:

    'use_featured_images' => array(
        'label'           => esc_html__( 'Use Featured Images?', 'foo_translation' ),
        'type'            => 'select',
        'options'         => array(
            'yes' => esc_html__( 'Yes', 'foo_translation' ),
            'no' => esc_html__( 'No', 'foo_translation' ),
        ),
        'default'         => 'no',
        'option_category' => 'basic_option',
        'description'     => esc_html__( 'Would you like to use the featured images in the background of the category cards.', 'foo_translation' ),
        'toggle_slug'     => 'main_content',
    ),
    
  • 检查浏览器控制台错误
    打开开发者工具(F12)查看控制台,若存在JS报错(如翻译未加载、字段结构解析失败),优先修复这些错误,Divi的设置面板依赖JS渲染,报错会直接导致字段无法显示。

  • 清理缓存
    清理Divi内部缓存(Divi > 主题选项 > 生成器 > 高级 > 清除缓存),同时清除浏览器缓存,Divi会缓存模块的设置结构,修改字段后需清缓存生效。

内容的提问来源于stack exchange,提问作者NickyLind

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 04:05:53