has_header_video()
Check whether a header video is set or not.
Uses: get_header_video_url()
Used By: has_custom_header()
1 time — 0.000058 sec (very fast) | 50000 times — 0.70 sec (very fast) | PHP 7.1.1, WP 4.7.1
No Hooks.
Return
true|false
. Whether a header video is set or not.
Usage
has_header_video();
Examples
#1 Display the header video
Check if the header video is there and if it should be displayed on the current page. If it's OK, we show the player with the video playing.
// check if there is a header video and it should show on the current page. if( has_header_video() && is_header_video_active() ){ the_custom_header_markup(); }
As a result, the HTML code of the video player will appear in place of this code, and the necessary scripts for the player will be connected to the page (to footer):
<div id="wp-custom-header" class="wp-custom-header"> <video id="wp-custom-header-video" autoplay="" loop="" width="954" height="1300" src="http://example.com/wp-content/uploads/2017/01/polina.mp4"></video> <button type="button" id="wp-custom-header-video-button" class="wp-custom-header-video-button wp-custom-header-video-play">Pause</button> </div>
Scripts in the footer:
<script type='text/javascript' src='http://example.com/wp-includes/js/wp-custom-header.min.js'></script> <script type='text/javascript' src='http://example.com/wp-includes/js/mediaelement/mediaelement-and-player.min.js'></script> <script type='text/javascript' src='http://example.com/wp-includes/js/mediaelement/wp-mediaelement.min.js'></script>
Notes
Changelog
Since 4.7.0 | Introduced. |
has_header_video() has header video code WP 6.6.1
function has_header_video() { return (bool) get_header_video_url(); }