is_header_video_active()WP 4.7.0

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

Hooks from the function

Return

true|false. True if the custom header video should be shown. False if not.

Usage

is_header_video_active();

Examples

0

#1 Let's display the header video

Check if the header video is there and if it should be displayed on the current page. If it's OK, we show the player with the video playing.

// check if there is a header video and it should show on the current page.
if( has_header_video() && is_header_video_active() ){
	the_custom_header_markup();
	// url to video - get_header_video_url()
}

As a result, the HTML code of the video player will appear in place of this code, and the necessary scripts for the player will be connected to the page (at the end):

<div id="wp-custom-header" class="wp-custom-header">
	<video id="wp-custom-header-video" autoplay="" loop="" width="954" height="1300" src="http://example.com/wp-content/uploads/2017/01/polina.mp4"></video>
	<button type="button" id="wp-custom-header-video-button" class="wp-custom-header-video-button wp-custom-header-video-play">Pause</button>
</div>

Scripts in the footer:

<script type='text/javascript' src='http://example.com/wp-includes/js/wp-custom-header.min.js'></script>

<script type='text/javascript' src='http://example.com/wp-includes/js/mediaelement/mediaelement-and-player.min.js'></script>

<script type='text/javascript' src='http://example.com/wp-includes/js/mediaelement/wp-mediaelement.min.js'></script>

Changelog

Since 4.7.0 Introduced.

is_header_video_active() code WP 6.4.3

function is_header_video_active() {
	if ( ! get_theme_support( 'custom-header', 'video' ) ) {
		return false;
	}

	$video_active_cb = get_theme_support( 'custom-header', 'video-active-callback' );

	if ( empty( $video_active_cb ) || ! is_callable( $video_active_cb ) ) {
		$show_video = true;
	} else {
		$show_video = call_user_func( $video_active_cb );
	}

	/**
	 * Filters whether the custom header video is eligible to show on the current page.
	 *
	 * @since 4.7.0
	 *
	 * @param bool $show_video 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()`.
	 */
	return apply_filters( 'is_header_video_active', $show_video );
}