Using WordPress ‘customize_controls_init’ PHP action

The customize_controls_init WordPress PHP action fires when Customizer controls are initialized, before scripts are enqueued.

Usage

add_action('customize_controls_init', 'your_function_name');
function your_function_name() {
    // your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: customize_controls_init

Examples

Load a custom stylesheet for the Customizer controls

add_action('customize_controls_init', 'enqueue_customizer_stylesheet');
function enqueue_customizer_stylesheet() {
    // Enqueue a custom stylesheet for the Customizer controls
    wp_enqueue_style('custom-customizer', get_stylesheet_directory_uri() . '/customizer.css');
}

Change the Customizer control’s background color

add_action('customize_controls_init', 'change_customizer_background_color');
function change_customizer_background_color() {
    // Change the Customizer control's background color
    wp_add_inline_style('customize-controls', 'body { background-color: #f8f8f8; }');
}

Add a custom JavaScript file to the Customizer controls

add_action('customize_controls_init', 'enqueue_customizer_script');
function enqueue_customizer_script() {
    // Enqueue a custom JavaScript file for the Customizer controls
    wp_enqueue_script('custom-customizer', get_stylesheet_directory_uri() . '/customizer.js', array('customize-controls'));
}

Remove the core Customizer CSS file

add_action('customize_controls_init', 'remove_core_customizer_css');
function remove_core_customizer_css() {
    // Remove the core Customizer CSS file
    wp_deregister_style('customize-controls');
}

Dequeue a script or style from the Customizer controls

add_action('customize_controls_init', 'dequeue_unnecessary_assets');
function dequeue_unnecessary_assets() {
    // Dequeue a script or style from the Customizer controls
    wp_dequeue_script('unnecessary-script');
    wp_dequeue_style('unnecessary-style');
}