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

How to use is_header_video_active filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
November 25, 2022
5 minutes read

“`html

is_header_video_active filter

Filters whether the custom header video is eligible to show on the current page.

To use is_header_video_active 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.

We prefer 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_is_header_video_active_defaults which takes 1 parameter and we registered it using add_filter. The first parameter is_header_video_active is the name of the hook, the second parameter modify_is_header_video_active_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 is_header_video_active filter.

Parameters

    Below the 1 parameter is required to use this hook.

  • $show_video : (bool) Whether the custom header video should be shown. Returns the value of the theme setting for the custom-header’s video-active-callback. If no callback is set, the default value is that of is_front_page().

Live Example

apply_filters( 'is_header_video_active', bool $show_video )

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

    function weplugins_modify_is_header_video_active_defaults($show_video) { 
        // Update the $show_video variable according to your website requirements and return this variable. 
        // You can modify the $show_video variable conditionally too if you want.
        return $show_video; 
    }
    // add the filter
    add_filter( "is_header_video_active", "weplugins_modify_is_header_video_active_defaults", 10, 1 );
    

To remove a hook callback, use the example below.

remove_filter( "is_header_video_active", "weplugins_modify_is_header_video_active_defaults", 10, 1 );

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

Access Premium WordPress Plugins

Example 1: Customizing Header Video Display

This example shows how to conditionally display the header video only on the front page.

    function weplugins_show_video_on_front_page($show_video) {
        if (is_front_page()) {
            return true;
        }
        return false;
    }
    add_filter("is_header_video_active", "weplugins_show_video_on_front_page", 10, 1);
    

Example 2: Disable Header Video on Mobile Devices

This example demonstrates how to disable the header video on mobile devices.

    function weplugins_disable_video_on_mobile($show_video) {
        if (wp_is_mobile()) {
            return false;
        }
        return $show_video;
    }
    add_filter("is_header_video_active", "weplugins_disable_video_on_mobile", 10, 1);
    

Example 3: Show Header Video Only for Logged-in Users

In this example, the header video will only be shown to logged-in users.

    function weplugins_video_for_logged_in_users($show_video) {
        if (is_user_logged_in()) {
            return true;
        }
        return false;
    }
    add_filter("is_header_video_active", "weplugins_video_for_logged_in_users", 10, 1);
    

If you need customization or have any questions, feel free to Contact Us.

“`

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.