get_header_image(): string|false
- Since
- 2.1.0
- Source
wp-includes/theme.php:1233
Compatibility
- WordPress
- since 2.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Return value
string|false
Performance profile
How much work a call to get_header_image() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 12–33
- Plugin surface
- 1 hook
- Called by
- 15
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 35.
Third-party callbacks on 'get_header_image' run inside this call, and their cost is not bounded by anything here.
15 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_header_image() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$url === "remove-header" | 12 | get_theme_support(), get_theme_mod() |
$url !== "remove-header" && !is_random_header_image() && !is_string($url) | 22 | get_theme_support(), get_theme_mod(), is_random_header_image(), apply_filters() |
$url !== "remove-header" && is_random_header_image() && !is_string($url) | 25 | get_theme_support(), get_theme_mod(), is_random_header_image(), get_random_header_image(), apply_filters() |
$url !== "remove-header" && !is_random_header_image() && is_string($url) | 30 | get_theme_support(), get_theme_mod(), is_random_header_image(), apply_filters(), set_url_scheme(), sanitize_url() |
$url !== "remove-header" && is_random_header_image() && is_string($url) | 33 | get_theme_support(), get_theme_mod(), is_random_header_image(), get_random_header_image(), apply_filters(), set_url_scheme(), sanitize_url() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 35 | 12–33 | 3 | |
| 8.5 | 35 | 12–33 | 3 | |
| 8.4 | 35 | 12–33 | 3 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 37 | 12–35 | 3 | |
| 8.2 | 37 | 12–35 | 3 | |
| 8.1 | 37 | 12–35 | 3 | |
| 7.4 | 37 | 12–35 | 3 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while get_header_image() runs, in this order:
Uses · 7
- get_theme_mod()Retrieves theme modification value for the active theme.
- get_theme_support()Gets the theme support arguments passed when registering that support.
- is_random_header_image()Checks if random header image is in use.
- get_random_header_image()Gets random header image URL from registered images in theme.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- sanitize_url()Sanitizes a URL for database or redirect usage.
- set_url_scheme()Sets the scheme for a URL.
Used by · 15
- Custom_Image_Header::step_1()Displays first step of custom header image page.
- _delete_attachment_theme_mod()Checks an attachment being deleted to see if it's a header or background image.
- get_header_image_tag()Creates image tag markup for a custom header image.
- get_header_video_settings()Retrieves header video settings.
- get_media_states()Retrieves an array of media states from an attachment.
- has_header_image()Checks whether a header image is set or not.
- header_image()Displays header image URL.
- twentyeleven_admin_header_image()Displays custom header image markup on the Appearance > Header admin panel.
- twentyfifteen_header_style()Styles the header image and text displayed on the blog.
- twentyfourteen_admin_header_image()Creates the custom header image markup displayed on the Appearance > Header screen.
- twentyfourteen_body_classes()Extends the default WordPress body classes.
- twentythirteen_admin_header_image()Outputs markup to be displayed on the Appearance > Header admin panel.
Show all 15
- twentythirteen_admin_header_style()Styles the header image displayed on the Appearance > Header admin panel.
- twentythirteen_header_style()Styles the header text displayed on the blog.
- twentytwelve_admin_header_image()Outputs markup to be displayed on the Appearance > Header admin panel.
Source code
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 ) );}Changelog
Introduced in 2.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/theme.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.