Using WordPress ‘customize_render_control’ PHP action

The customize_render_control WordPress PHP action fires just before the current Customizer control is rendered.

Usage

add_action('customize_render_control', 'your_custom_function');
function your_custom_function($control) {
    // your custom code here
}

Parameters

  • $control (WP_Customize_Control): The current Customizer control instance.

More information

See WordPress Developer Resources: customize_render_control

Examples

Change Control Label

Change the label of a Customizer control based on its ID.

add_action('customize_render_control', 'change_control_label');
function change_control_label($control) {
    if ($control->id == 'your_control_id') {
        $control->label = 'New Control Label';
    }
}

Add Custom CSS Class

Add a custom CSS class to the control container.

add_action('customize_render_control', 'add_custom_css_class');
function add_custom_css_class($control) {
    $control->container_class .= ' custom-css-class';
}

Add Custom Attribute

Add a custom attribute to the control input element.

add_action('customize_render_control', 'add_custom_attribute');
function add_custom_attribute($control) {
    $control->input_attrs['data-custom-attribute'] = 'custom-value';
}

Add Description

Add a custom description to a specific control.

add_action('customize_render_control', 'add_control_description');
function add_control_description($control) {
    if ($control->id == 'your_control_id') {
        $control->description = 'This is a custom description.';
    }
}

Modify Control Type

Change the control type based on a condition.

add_action('customize_render_control', 'modify_control_type');
function modify_control_type($control) {
    if (some_condition()) {
        $control->type = 'radio';
    } else {
        $control->type = 'select';
    }
}