Using WordPress ‘customize_render_panel_{$this->id}’ PHP action

The customize_render_panel_{$this->id} WordPress PHP action fires before rendering a specific Customizer panel. The dynamic portion of the hook name, $this->id, refers to the ID of the specific Customizer panel to be rendered.

Usage

add_action('customize_render_panel_example_panel', 'my_custom_render_function');
function my_custom_render_function() {
    // your custom code here
}

Parameters

None

More information

See WordPress Developer Resources: customize_render_panel_{$this->id}

Examples

Changing the panel title

Modify the panel title before rendering the Customizer panel.

add_action('customize_render_panel_example_panel', 'change_panel_title');
function change_panel_title() {
    // Change panel title
    global $wp_customize;
    $panel = $wp_customize->get_panel('example_panel');
    $panel->title = 'New Panel Title';
}

Adding a custom CSS class

Add a custom CSS class to the specific Customizer panel.

add_action('customize_render_panel_example_panel', 'add_custom_css_class');
function add_custom_css_class() {
    // Add custom CSS class
    echo '<style>.example_panel { background-color: red; }</style>';
}

Adding a custom JavaScript

Add custom JavaScript to the specific Customizer panel.

add_action('customize_render_panel_example_panel', 'add_custom_js');
function add_custom_js() {
    // Add custom JavaScript
    echo '<script>console.log("Custom JS for example_panel");</script>';
}

Displaying a notice

Display a custom notice in the specific Customizer panel.

add_action('customize_render_panel_example_panel', 'display_notice');
function display_notice() {
    // Display custom notice
    echo '<div class="notice">This is a custom notice for the example panel.</div>';
}

Conditionally rendering the panel

Render the specific Customizer panel only for certain users.

add_action('customize_render_panel_example_panel', 'conditionally_render_panel');
function conditionally_render_panel() {
    // Render panel for admins only
    if (!current_user_can('manage_options')) {
        wp_die('Sorry, you are not allowed to access this panel.');
    }
}