The customize_render_section WordPress PHP action fires before rendering a Customizer section, allowing you to modify the section before it’s displayed.
Usage
add_action('customize_render_section', 'your_custom_function', 10, 1);
function your_custom_function($section) {
// your custom code here
return $section;
}
Parameters
- $section (WP_Customize_Section): The WP_Customize_Section instance that you can modify or interact with.
More information
See WordPress Developer Resources: customize_render_section
Examples
Add custom HTML to a section
Add extra HTML content to a specific section in the Customizer.
add_action('customize_render_section', 'add_custom_html_to_section', 10, 1);
function add_custom_html_to_section($section) {
if ('your_section_id' === $section->id) {
echo '<div class="custom-html">Your custom HTML here.</div>';
}
}
Change section title
Modify the title of a specific section in the Customizer.
add_action('customize_render_section', 'change_section_title', 10, 1);
function change_section_title($section) {
if ('your_section_id' === $section->id) {
$section->title = 'New Section Title';
}
}
Add custom CSS class to a section
Add a custom CSS class to a specific section in the Customizer.
add_action('customize_render_section', 'add_custom_css_class_to_section', 10, 1);
function add_custom_css_class_to_section($section) {
if ('your_section_id' === $section->id) {
$section->container_class .= ' custom-class';
}
}
Change section description
Modify the description of a specific section in the Customizer.
add_action('customize_render_section', 'change_section_description', 10, 1);
function change_section_description($section) {
if ('your_section_id' === $section->id) {
$section->description = 'New section description.';
}
}
Hide a section based on user role
Hide a specific section in the Customizer for users with a certain role.
add_action('customize_render_section', 'hide_section_for_role', 10, 1);
function hide_section_for_role($section) {
$user = wp_get_current_user();
if (in_array('your_role', $user->roles) && 'your_section_id' === $section->id) {
$section->active_callback = '__return_false';
}
}