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

How to use mejs_settings filter in WordPress

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

Welcome to the world of WordPress hooks! Let’s dive into the mejs_settings filter. This hook is your gateway to customizing the MediaElement configuration settings in WordPress. As an Indian developer, I can tell you that the key to mastering hooks is practice and experimentation. So, let’s get started!

To use the mejs_settings filter, you’ll need to register it using add_filter. The best practice is to write this code in the functions.php file of your activated theme or in a custom WordPress plugin. At WePlugins, we always recommend creating a custom plugin for your hooks to ensure nothing breaks when you update your WordPress theme in the future.

Here’s how you can define a function, modify_mejs_settings_defaults, which takes one parameter. Then, register it using add_filter. The first parameter, mejs_settings, is the hook’s name. The second parameter is the function name to be called. The third is the priority of calling the hook if it’s used multiple times, and the last is the number of arguments (if any) to be passed to the registered function.

Sometimes, you might need to remove a registered hook. In that case, you can use remove_filter to remove the mejs_settings filter.

Example 1: Applying the Filter

Below is an example of how you can use this hook.

    function weplugins_modify_mejs_settings_defaults($mejs_settings) { 
        // Update the $mejs_settings variable according to your website requirements and return this variable.
        return $mejs_settings; 
    }
    // add the filter
    add_filter( "mejs_settings", "weplugins_modify_mejs_settings_defaults", 10, 1 );
    

Example 2: Removing the Filter

To remove a hook callback, use the example below.

    remove_filter( "mejs_settings", "weplugins_modify_mejs_settings_defaults", 10, 1 );
    

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

Example 3: Conditional Modifications

Modify the $mejs_settings variable conditionally based on your website requirements.

    function weplugins_modify_mejs_settings_defaults($mejs_settings) { 
        if (is_page('video-page')) {
            // Customize settings for a specific page
            $mejs_settings['feature'] = 'my_custom_feature';
        }
        return $mejs_settings; 
    }
    add_filter( "mejs_settings", "weplugins_modify_mejs_settings_defaults", 10, 1 );
    

Access Premium WordPress Plugins

Contact Us

If you’re having any trouble using this hook or need customization, please 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.