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