最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customization - How do I remove a customiser option from a parent theme in a child theme?

programmeradmin0浏览0评论

Let's say there is a theme that you like but you want to make some changes. You make a child-theme. At least you do if you follow good advice. So now you have a child theme. You are happy with it and want to share. There is just one small problem - one of the controls in the customizer makes no-sense with the changes you have made.

How do you make the customizer control from the parent theme go away for your child theme?

Let's say there is a theme that you like but you want to make some changes. You make a child-theme. At least you do if you follow good advice. So now you have a child theme. You are happy with it and want to share. There is just one small problem - one of the controls in the customizer makes no-sense with the changes you have made.

How do you make the customizer control from the parent theme go away for your child theme?

Share Improve this question asked Jul 9, 2019 at 0:07 Matthew Brown aka Lord MattMatthew Brown aka Lord Matt 1,0683 gold badges13 silver badges34 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 6

From the documentation:

To add, remove, or modify any Customizer object, and to access the Customizer Manager, use the customize_register hook:

function themeslug_customize_register( $wp_customize ) {
  // Do stuff with $wp_customize, the WP_Customize_Manager object.
}
add_action( 'customize_register', 'themeslug_customize_register' );

The Customizer Manager provides add_, get_, and remove_ methods for each Customizer object type; each works with an id. The get_ methods allow for direct modification of parameters specified when adding a control.

add_action('customize_register','my_customize_register');
function my_customize_register( $wp_customize ) {
  $wp_customize->add_panel();
  $wp_customize->get_panel();
  $wp_customize->remove_panel();

  $wp_customize->add_section();
  $wp_customize->get_section();
  $wp_customize->remove_section();

  $wp_customize->add_setting();
  $wp_customize->get_setting();
  $wp_customize->remove_setting();

  $wp_customize->add_control();
  $wp_customize->get_control();
  $wp_customize->remove_control();
}

So in your case, you can remove a control using WP_Customize_Manager::remove_control().

Example for the Twenty Nineteen theme:

function my_theme_customize_register( $wp_customize ) {
    // Remove the Colors -> Primary Color option.
    $wp_customize->remove_control( 'primary_color' );
}
add_action( 'customize_register', 'my_theme_customize_register', 11 );
发布评论

评论列表(0)

  1. 暂无评论