Using WordPress ‘get_header_video_settings()’ PHP function

The get_header_video_settings() WordPress PHP function retrieves the header video settings.

Usage

To use the function, simply call it like this:

$video_settings = get_header_video_settings();

Parameters

This function does not have any parameters.

More information

See WordPress Developer Resources: get_header_video_settings

Examples

Display header video URL

Retrieve header video settings and display the video URL.

$video_settings = get_header_video_settings();
echo 'Header video URL: ' . $video_settings['videoUrl'];

Show header video thumbnail

Retrieve header video settings and display the video thumbnail image.

$video_settings = get_header_video_settings();
echo '<img src="' . $video_settings['thumbnailUrl'] . '" alt="Video Thumbnail">';

Conditional display of header video

Display header video only if it is set in the customizer.

$video_settings = get_header_video_settings();
if (!empty($video_settings['videoUrl'])) {
    echo '<video src="' . $video_settings['videoUrl'] . '" autoplay loop></video>';
}

Display header video with custom width and height

Retrieve header video settings and display the video with custom dimensions.

$video_settings = get_header_video_settings();
echo '<video src="' . $video_settings['videoUrl'] . '" width="640" height="360" autoplay loop></video>';

Check if header video is an external URL

Check if the header video is an external URL (e.g., YouTube, Vimeo) or a local video file.

$video_settings = get_header_video_settings();
$is_external = (bool) $video_settings['externalVideo'];
if ($is_external) {
    echo 'The header video is an external URL.';
} else {
    echo 'The header video is a local file.';
}