The ‘get_header_video_url‘ PHP filter is a WordPress function that allows you to modify the header video URL that is displayed on your website.
On this pageJump to a section
This filter is useful if you want to change the video URL or add additional functionality to the header video.
Usage
To use the ‘get_header_video_url’ PHP filter, you need to add the following code to your theme’s functions.php file:
function my_header_video_url( $video_url ) {
// Modify the header video URL here
return $video_url;
}
add_filter( 'get_header_video_url', 'my_header_video_url' );
Parameters
The ‘get_header_video_url’ PHP filter accepts one parameter:
$video_url(string): The URL of the header video.
Examples
Here are some practical examples of how you can use the ‘get_header_video_url’ PHP filter:
Example 1: Change the header video URL
function my_header_video_url( $video_url ) {
// Change the header video URL to a different video
$video_url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
return $video_url;
}
add_filter( 'get_header_video_url', 'my_header_video_url' );
This code changes the header video URL to a different video.
Example 2: Add a query parameter to the header video URL
function my_header_video_url( $video_url ) {
// Add a query parameter to the header video URL
$video_url = add_query_arg( 'autoplay', '1', $video_url );
return $video_url;
}
add_filter( 'get_header_video_url', 'my_header_video_url' );
This code adds a query parameter to the header video URL to autoplay the video.
Example 3: Check if the header video URL is empty
function my_header_video_url( $video_url ) {
// Check if the header video URL is empty
if ( empty( $video_url ) ) {
$video_url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
}
return $video_url;
}
add_filter( 'get_header_video_url', 'my_header_video_url' );
This code checks if the header video URL is empty and sets a default video URL if it is.
Example 4: Remove the header video
function my_header_video_url( $video_url ) {
// Remove the header video
$video_url = '';
return $video_url;
}
add_filter( 'get_header_video_url', 'my_header_video_url' );
This code removes the header video by setting the video URL to an empty string.
Example 5: Add a video URL based on the current page
function my_header_video_url( $video_url ) {
// Add a video URL based on the current page
if ( is_front_page() ) {
$video_url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
} else {
$video_url = 'https://www.youtube.com/watch?v=6Dh-RL__uN4';
}
return $video_url;
}
add_filter( 'get_header_video_url', 'my_header_video_url' );
This code adds a video URL based on the current page. If the current page is the front page, it sets the video URL to a Rick Astley video. If it’s any other page, it sets the video URL to a different video.