get_header_video_url()WP 4.7.0

Retrieve header video URL for custom header.

Uses a local video if present, or falls back to an external video.

Hooks from the function

Return

String|false. Header video URL or false if there is no video.

Usage

get_header_video_url();

Examples

0

#1 Display the header video if there is one [auto-translate]

$url = get_header_video_url();
if( $url ){
	echo wp_video_shortcode( array(
		'src'      => $url,
		'poster'   => '',
		'height'   => 400,
		'width'    => 600,
	) );
}

The result will be the following HTML code:

<div style="width:600px;" class="wp-video">
	<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->
	<video class="wp-video-shortcode" id="video-298-1" width="600" height="400" preload="metadata" controls="controls">
		<source type="video/mp4" src="http://example.com/wp-content/uploads/2017/01/polina.mp4?_=1" />
		<a href="http://example.com/wp-content/uploads/2017/01/polina.mp4">http://example.com/wp-content/uploads/2017/01/polina.mp4</a>
	</video>
</div>

Changelog

Since 4.7.0 Introduced.

get_header_video_url() code WP 6.4.3

function get_header_video_url() {
	$id = absint( get_theme_mod( 'header_video' ) );

	if ( $id ) {
		// Get the file URL from the attachment ID.
		$url = wp_get_attachment_url( $id );
	} else {
		$url = get_theme_mod( 'external_header_video' );
	}

	/**
	 * Filters the header video URL.
	 *
	 * @since 4.7.3
	 *
	 * @param string $url Header video URL, if available.
	 */
	$url = apply_filters( 'get_header_video_url', $url );

	if ( ! $id && ! $url ) {
		return false;
	}

	return sanitize_url( set_url_scheme( $url ) );
}