Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use customize_loaded_components filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
July 4, 2023
5 minutes read

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.

Access Premium WordPress Plugins

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.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

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.