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

How to use disable_formats_dropdown filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
May 22, 2023
5 minutes read

Are you looking to customize the post list table in WordPress by removing the ‘Formats’ drop-down? The disable_formats_dropdown filter hook might just be what you need. It’s a handy tool for developers wanting to tweak WordPress functionalities. Let’s dive into how you can use this hook in your projects.

Example 1: Basic Usage of disable_formats_dropdown

Here’s a straightforward example of how you can use the disable_formats_dropdown hook. This example demonstrates registering the hook using the add_filter function.

    function weplugins_modify_disable_formats_dropdown_defaults($disable, $post_type) { 
        // Customize the $disable variable as per your requirements
        return $disable; 
    }
    // Add the filter
    add_filter("disable_formats_dropdown", "weplugins_modify_disable_formats_dropdown_defaults", 10, 2);
    

Example 2: Conditionally Disabling Formats Dropdown

If you want to conditionally disable the formats dropdown based on the post type, this example will guide you through it.

    function weplugins_conditionally_disable_formats_dropdown($disable, $post_type) {
        if ($post_type === 'custom_post_type') {
            $disable = true; // Disable for 'custom_post_type'
        }
        return $disable;
    }
    add_filter("disable_formats_dropdown", "weplugins_conditionally_disable_formats_dropdown", 10, 2);
    

Example 3: Removing a Hook Callback

At times, you might need to remove a previously registered hook. This example shows how to use remove_filter for that purpose.

    // Remove the filter
    remove_filter("disable_formats_dropdown", "weplugins_modify_disable_formats_dropdown_defaults", 10, 2);
    

When removing a hook, ensure that the callback function name, priority, and number of arguments match those used when adding the hook.

Got customization needs or questions? Contact Us for expert assistance.

Access Premium WordPress Plugins

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.