How to get a custom header video URL in WordPress

The get_header_video_url function in WordPress is designed to retrieve the URL of the custom header video. This function is part of the WordPress Custom Header feature, which allows users to customize the header of their website by adding images or videos.

The get_header_video_url function is specifically used when a video has been set as the header. It returns the URL of the header video, allowing it to be used elsewhere on the website if required.

This function is a part of the WordPress Core and is defined in the wp-includes/theme.php file. It does not accept any parameters and returns a string containing the URL of the header video. If no video is set, the function will return an empty string.

It’s important to note that the get_header_video_url function will only return a URL if the video is hosted on the website itself or on a service that is supported by WordPress, such as YouTube or Vimeo. If the video is hosted on an unsupported service, the function will not return a URL.

Parameters

The get_header_video_url function in WordPress does not accept any parameters.

Return Value

The get_header_video_url function yields either a string containing the URL of the header video or a boolean false if no video is present.

Examples

How to Display Header Video URL

This example shows how to use the get_header_video_url function to display the URL of the header video.

 $header_video_url = get_header_video_url();
 if ($header_video_url) {
 echo '<p>Header Video URL: ' . $header_video_url . '</p>';
 } else {
 echo '<p>No header video found.</p>';
 }

How to Use get_header_video_url Function to Embed a Video

This example shows how to use the get_header_video_url function to embed a video in a web page using the returned URL.

$header_video_url = get_header_video_url();
if ($header_video_url) {
 echo '<video width="320" height="240" controls>
 <source src="' . $header_video_url . '" type="video/mp4">
 Your browser does not support the video tag.
 </video>';
} else {
 echo '<p>No header video found.</p>';
}

Conclusion

The WordPress function get_header_video_url is a built-in function that returns the URL of the current custom header video. This function can be utilized when developers need to retrieve the URL of the video set in the customizer under the header media option. The URL returned by this function can then be used in various ways, such as for displaying the video on a page, or for processing in other functions or scripts.

Related WordPress Functions