get_header_image()WP 2.1.0

Retrieve header image for custom header.

Used By: header_image()
Hooks from the function

Return

String|false.

Usage

get_header_image();

Examples

0

#1 Display an img image tag for the header

<img src="<?php echo get_header_image(); ?>" alt="<?php bloginfo('title'); ?>">

Before using this, check out get_header_image_tag() first.

It will return an tag including the srcset attributes for responsive images.

0

#2 Display IMG tag using the_custom_header_markup()

the_custom_header_markup(); 

Can be use in place of:

<img alt="" src="<?php header_image(); ?>" 
	width="<?php echo get_custom_header()->width; ?>" 
	height="<?php echo get_custom_header()->height; ?>"
>

Changelog

Since 2.1.0 Introduced.

get_header_image() code WP 6.4.3

function get_header_image() {
	$url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) );

	if ( 'remove-header' === $url ) {
		return false;
	}

	if ( is_random_header_image() ) {
		$url = get_random_header_image();
	}

	/**
	 * Filters the header image URL.
	 *
	 * @since 6.1.0
	 *
	 * @param string $url Header image URL.
	 */
	$url = apply_filters( 'get_header_image', $url );

	if ( ! is_string( $url ) ) {
		return false;
	}

	$url = trim( $url );
	return sanitize_url( set_url_scheme( $url ) );
}