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.
WordPress hooks are like secret gateways that let you modify the core functionalities of WordPress without altering the core files. In this guide, we’ll dive into the customize_loaded_components filter, which is quite handy for developers looking to exclude specific Core components from being instantiated. Let’s explore how you can wield this hook to customize your WordPress site effortlessly!
Example 1: Remove Core ‘Menus’ Panel
If you want to remove the core ‘Menus’ panel from the Customizer, here’s a neat trick using the customize_loaded_components filter.
/** * Removes the core 'Menus' panel from the Customizer. * * @param array $components Core Customizer components list. * @return array (Maybe) modified components list. */ function weplugins_remove_nav_menus_panel( $components ) { $i = array_search( 'nav_menus', $components ); if ( false !== $i ) { unset( $components[ $i ] ); } return $components; } add_filter( "customize_loaded_components", "weplugins_remove_nav_menus_panel", 10, 1 );
Example 2: Modify Components Conditionally
Let’s say you need to tweak the components based on certain conditions. Here’s how you can do it.
function weplugins_modify_customize_loaded_components_defaults($components, $manager) { // Modify the $components array based on your conditions if ( some_condition() ) { // Update components } return $components; } add_filter( "customize_loaded_components", "weplugins_modify_customize_loaded_components_defaults", 10, 2 );
Example 3: Removing a Hook Callback
Need to remove a registered hook? You can easily do that with remove_filter. Here’s an example.
remove_filter( "customize_loaded_components", "weplugins_modify_customize_loaded_components_defaults", 10, 2 );
Ensure you provide the same callback function name, priority, and number of arguments while removing the hook callback.
Contact Us for Customization
If you’re having any trouble using this hook or need customizations, don’t hesitate to reach out to us. Visit our Contact Us page to get in touch.
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.