This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
customizer_widgets_section_args filter
Filters Customizer widget section arguments for a given sidebar.
To use customizer_widgets_section_args filter, first you have to register it using add_filter. You can write this code into functions.php of your activated theme or in a custom WordPress Plugin. We at WePlugins always prefer to create a custom WordPress Plugin while using hooks so nothing breaks when you update your WordPress Theme in the future.
In the below live example, we have defined a function modify_customizer_widgets_section_args_defaults which takes 3 parameters and we registered using add_filter. The first parameter customizer_widgets_section_args is the name of the hook, the second parameter modify_customizer_widgets_section_args_defaults is the name of the function which needs to be called, the third parameter is the priority of calling the hook if the same hook is used multiple times, and the last parameter is the number of arguments (if any) to be passed in the registered function.
Sometimes, you have to remove a registered hook, so you can use remove_filter to remove customizer_widgets_section_args filter.
Parameters
- $section_args: (array) Array of Customizer widget section arguments.
- $section_id: (string) Customizer section ID.
- $sidebar_id: (int|string) Sidebar ID.
Below are the 3 parameters required to use this hook.
Live Example
apply_filters('customizer_widgets_section_args', array $section_args, string $section_id, int|string $sidebar_id)
Below is an example of how you can use this hook.
function weplugins_modify_customizer_widgets_section_args_defaults($section_args, $section_id, $sidebar_id) { // Update the $section_args variable according to your website requirements and return this variable. You can modify the $section_args variable conditionally too if you want. return $section_args; } // Add the filter add_filter('customizer_widgets_section_args', 'weplugins_modify_customizer_widgets_section_args_defaults', 10, 3);
Example 1: Modifying Section Title
In this example, we modify the section title based on the sidebar ID.
function weplugins_modify_customizer_widgets_section_title($section_args, $section_id, $sidebar_id) { if ($sidebar_id == 'sidebar-1') { $section_args['title'] = 'Custom Sidebar Title'; } return $section_args; } add_filter('customizer_widgets_section_args', 'weplugins_modify_customizer_widgets_section_title', 10, 3);
Example 2: Adding a Description
Here, we add a custom description to the widget section.
function weplugins_add_customizer_widgets_section_description($section_args, $section_id, $sidebar_id) { $section_args['description'] = 'This is a custom description for the widget section.'; return $section_args; } add_filter('customizer_widgets_section_args', 'weplugins_add_customizer_widgets_section_description', 10, 3);
Example 3: Customizing Section Priority
In this example, we change the priority of the widget section.
function weplugins_customize_section_priority($section_args, $section_id, $sidebar_id) { $section_args['priority'] = 20; return $section_args; } add_filter('customizer_widgets_section_args', 'weplugins_customize_section_priority', 10, 3);
To remove a hook callback, use the example below.
remove_filter('customizer_widgets_section_args', 'weplugins_modify_customizer_widgets_section_args_defaults', 10, 3);
Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.
Contact Us
If you need any customization or have any trouble using this hook, please contact us.
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.