has_header_image()WP 4.2.0

Checks if a header image is set for the site (custom header).

The function returns true if a header image is set for the current site through theme settings or through the customizer. If the image is not set — it returns false.

It is often used before outputting the site header to avoid empty <img> tags.

In order to have the ability to set a header image for the theme, theme support for custom-header must be enabled — add_theme_support( 'custom-header' ).

Do not confuse with get_header_image(), which returns the image URL.

Can be used together with has_header_video() for combined display logic.

No Hooks.

Returns

true|false. Logical true or false.

Usage

has_header_image();

Examples

0

#1 Let's check if the theme has a header picture

Display a picture if there is one:

if( has_header_image() ){
	echo sprintf( '<img src="%s" alt="%s">', 
		esc_url( get_header_image() ),
		esc_attr( get_bloginfo( 'title' ) )
	);
}

See also:

0

#2 Display of image or video

if ( has_header_video() && is_header_video_active() ) {
	the_custom_header_markup();
}
elseif ( has_header_image() ) {
	echo '<img src="' . esc_url( get_header_image() ) . '" alt="">';
}

Notes

Changelog

Since 4.2.0 Introduced.

has_header_image() code WP 6.9

function has_header_image() {
	return (bool) get_header_image();
}