has_custom_header()
Check whether a custom header is set or not.
1 time — 0.000148 sec (fast) | 50000 times — 2.97 sec (fast) | PHP 7.1.0, WP 4.7
No Hooks.
Return
true|false
. True if a custom header is set. False if not.
Usage
has_custom_header();
Examples
#1 Check if there is a image or a video for the site Header
If there is, we will display the HTML code:
if( has_custom_header() ){ the_custom_header_markup(); }
For a image it will output HTML:
<div id="wp-custom-header" class="wp-custom-header"> <img src="http://example.com/wp-content/uploads/2016/05/image.jpg" width="954" height="1300" alt="Test Site srcset="http://example.com/wp-content/uploads/2016/05/image.jpg 954w, http://example.com/wp-content/uploads/2016/05/image-220x300.jpg 220w, http://example.com/wp-content/uploads/2016/05/image-768x1047.jpg 768w, http://example.com/wp-content/uploads/2016/05/image-751x1024.jpg 751w" sizes="(max-width: 954px) 100vw, 954px" /> </div>
The following HTML will be output for the video. And also in the footer will be connected scripts. HTML video is created by the script and replaces the HTML images.
<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>
Changelog
Since 4.7.0 | Introduced. |
has_custom_header() has custom header code WP 6.7.1
function has_custom_header() { if ( has_header_image() || ( has_header_video() && is_header_video_active() ) ) { return true; } return false; }