header_image()
Outputs the URL of the header image, which is set in the theme settings.
Before outputting the URL, it is sanitized using esc_url().
Works only when the theme has the ability to set a header image.
Use get_header_image() when you need to get the URL into a variable.
Uses: get_header_image()
1 time — 0.005023 sec (very slow) | 50000 times — 3.03 sec (fast)
No Hooks.
Returns
null. Will not output anything if:
-
the current theme does not support a header image. To enable such support, read here: add_theme_support().
- no header image is set for the current theme. It is set in the settings:
Appearance > Customize(Внешний вид > Customize).
Usage
header_image();
Examples
#1 Display an img image tag for the header
<img src="<?php header_image(); ?>" alt="<?php bloginfo('title'); ?>">
Changelog
| Since 2.1.0 | Introduced. |
header_image() header image code WP 6.9.1
function header_image() {
$image = get_header_image();
if ( $image ) {
echo esc_url( $image );
}
}