The get_header_video_url() WordPress PHP function retrieves the header video URL for a custom header. It uses a local video if present, or falls back to an external video.
Usage
$video_url = get_header_video_url(); echo $video_url;
Parameters
- None
More information
See WordPress Developer Resources: get_header_video_url
Examples
Display the header video URL
This example retrieves the header video URL and displays it on the page.
$video_url = get_header_video_url(); echo '<p>Header video URL: ' . $video_url . '</p>';
Create an HTML video element
This example retrieves the header video URL and creates an HTML video element with the source set to the URL.
$video_url = get_header_video_url(); echo '<video width="320" height="240" controls> <source src="' . $video_url . '" type="video/mp4"> </video>';
Check if a header video exists
This example checks if a header video exists, and if it does, it displays a message.
$video_url = get_header_video_url(); if ($video_url) { echo '<p>A header video exists!</p>'; }
Display video URL only for local videos
This example checks if the header video URL is from the local site and only displays it if it is.
$video_url = get_header_video_url(); $site_url = get_site_url(); if (strpos($video_url, $site_url) === 0) { echo '<p>Local header video URL: ' . $video_url . '</p>'; }
Create a fallback message
This example checks if a header video URL exists, and if it doesn’t, it displays a fallback message.
$video_url = get_header_video_url(); if ($video_url) { echo '<p>Header video URL: ' . $video_url . '</p>'; } else { echo '<p>No header video found.</p>'; }