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?

4

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 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.