get_header_image(): string|false

Retrieves header image for custom header.

Return

string|false

Source

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 ) );
}

Hooks

apply_filters( ‘get_header_image’, string $url )

Filters the header image URL.

Changelog

VersionDescription
2.1.0Introduced.

User Contributed Notes

  1. Skip to note 5 content

    Before using this, check out get_header_image_tag() first. That’s a new function in 4.4 that’ll return an tag including the srcset attributes for responsive images.

    https://developer.wordpress.org/reference/functions/get_header_image_tag/

You must log in before being able to contribute a note or feedback.