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

How to use current_theme_supports-feature filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
June 15, 2023
5 minutes read

 

current_theme_supports-feature filter

The dynamic portion of the hook name, $feature, refers to the specific theme feature. See add_theme_support() for the list of possible values.

To use current_theme_supports-feature 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.

WePlugins always prefers 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_current_theme_supports-feature_defaults which takes 3 parameters and we registered using add_filter. The first parameter current_theme_supports-feature is the name of the hook, the second parameter modify_current_theme_supports-feature_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 current_theme_supports-feature filter.

Example 1: Basic Hook Usage

This example demonstrates basic usage of the current_theme_supports-feature filter.

    function weplugins_modify_current_theme_supports_feature_defaults($supports, $args, $feature) { 
        // Update the $supports variable according to your website requirements and return this variable.
        return $supports; 
    }
    // add the filter
    add_filter("current_theme_supports-feature", "weplugins_modify_current_theme_supports_feature_defaults", 10, 3);
    

Example 2: Removing a Hook

To remove a hook callback, use the example below.

    remove_filter("current_theme_supports-feature", "weplugins_modify_current_theme_supports_feature_defaults", 10, 3);
    

Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.

Example 3: Conditional Support Modification

This example shows how you can modify the $supports variable conditionally.

    function weplugins_modify_current_theme_supports_feature_conditionally($supports, $args, $feature) { 
        if ($feature === 'custom-feature') {
            $supports = false;
        }
        return $supports; 
    }
    add_filter("current_theme_supports-feature", "weplugins_modify_current_theme_supports_feature_conditionally", 10, 3);
    

Access Premium WordPress Plugins

Contact Us

If you need customization or have any trouble using this hook, contact us and we’d be happy to assist you.

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.