首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress Customizer保持隐藏自定义分区

Wordpress Customizer保持隐藏自定义分区
EN

Stack Overflow用户
提问于 2019-08-22 22:17:28
回答 1查看 307关注 0票数 1

我有添加定制化部分和选项的自定义插件。这些部分可以在定制器屏幕上短暂地看到,但随后会消失。这种行为在所有主题上都会发生(我在其他网站上使用我的插件)。

也许是因为主题中还没有使用设置字段,但即使我创建了自己的主题(这个插件主要用于这个主题),并在主题代码中的某个地方添加了echo get_theme_mod('setting-key'),这些部分仍然会被wordpress隐藏。

我有干净的Wordpress安装版本5.2.2,使用默认的二十九主题,只有jQuery更新插件活动。我已经检查了所有JS代码的潜在错误和任何隐藏发生的情况,但我这方面没有任何东西可以导致这一点。

这就是我在customize_register钩子中添加部分的方式:

代码语言:javascript
复制
add_action('customize_register', 'setup_section');
function setup_section($wp_customize){
  // Add section
  $wp_customize->add_section('section_id', array(
    'title'    => 'Section Title',
    'priority' => 160,
  ));
  // Add settings for a field
  $wp_customize->add_setting('setting_id', array(
    'default'   => '',
    'transport' => 'refresh',
  ));
  // Add the field into a section and assign setting id
  $wp_customize->add_control('setting_id', array(
    'label'    => 'Option Label',
    'section'  => 'section_id',
    'settings' => 'setting_id',
    'type'     => 'text',
  ));
}

PHP代码正常工作,但是在页面加载之后,我的所有自定义部分都添加了display: none;内联css,并且这些部分消失了。

任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

发布于 2021-02-28 12:56:48

自定义部分保持隐藏的另一个原因是当它们没有任何控件时。当某个部分为空时,默认情况下WordPress会将其隐藏。

下面是用一个控件在Customizer中添加一个部分的完整工作代码:

代码语言:javascript
复制
function mytheme_customize_register( $wp_customize ) {
    
    $wp_customize->add_section('footer_settings_section', array(
        'title'          => 'Footer Text Section'
    ));

    $wp_customize->add_setting('text_setting', array(
        'default'        => 'Default Text For Footer Section',
    ));

    $wp_customize->add_control('text_setting', array(
        'label'   => 'Footer Text Here',
        'section' => 'footer_settings_section',
        'type'    => 'textarea',
    ));

    
 }
 add_action( 'customize_register', 'mytheme_customize_register' );
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57611426

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档