Title: get_header_image
Published: April 25, 2014
Last modified: August 20, 2026

---

# get_header_image(): string|false

## In this article

 * [Return](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#user-contributed-notes)

Retrieves header image for custom header.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#return)󠁿

 string|false

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/file/wp-includes/theme.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/theme.php#L1230)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/theme.php#L1230-L1256)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#hooks)󠁿

 [apply_filters( ‘get_header_image’, string $url )](https://developer.wordpress.org/reference/hooks/get_header_image/)

Filters the header image URL.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#related)󠁿

| Uses | Description | 
| [get_theme_support()](https://developer.wordpress.org/reference/functions/get_theme_support/)`wp-includes/theme.php` |

Gets the theme support arguments passed when registering that support.

  | 
| [is_random_header_image()](https://developer.wordpress.org/reference/functions/is_random_header_image/)`wp-includes/theme.php` |

Checks if random header image is in use.

  | 
| [get_random_header_image()](https://developer.wordpress.org/reference/functions/get_random_header_image/)`wp-includes/theme.php` |

Gets random header image URL from registered images in theme.

  | 
| [get_theme_mod()](https://developer.wordpress.org/reference/functions/get_theme_mod/)`wp-includes/theme.php` |

Retrieves theme modification value for the active theme.

  | 
| [set_url_scheme()](https://developer.wordpress.org/reference/functions/set_url_scheme/)`wp-includes/link-template.php` |

Sets the scheme for a URL.

  | 
| [sanitize_url()](https://developer.wordpress.org/reference/functions/sanitize_url/)`wp-includes/formatting.php` |

Sanitizes a URL for database or redirect usage.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#)

| Used by | Description | 
| [get_media_states()](https://developer.wordpress.org/reference/functions/get_media_states/)`wp-admin/includes/template.php` |

Retrieves an array of media states from an attachment.

  | 
| [get_header_video_settings()](https://developer.wordpress.org/reference/functions/get_header_video_settings/)`wp-includes/theme.php` |

Retrieves header video settings.

  | 
| [get_header_image_tag()](https://developer.wordpress.org/reference/functions/get_header_image_tag/)`wp-includes/theme.php` |

Creates image tag markup for a custom header image.

  | 
| [has_header_image()](https://developer.wordpress.org/reference/functions/has_header_image/)`wp-includes/theme.php` |

Checks whether a header image is set or not.

  | 
| [Custom_Image_Header::step_1()](https://developer.wordpress.org/reference/classes/custom_image_header/step_1/)`wp-admin/includes/class-custom-image-header.php` |

Displays first step of custom header image page.

  | 
| [_delete_attachment_theme_mod()](https://developer.wordpress.org/reference/functions/_delete_attachment_theme_mod/)`wp-includes/theme.php` |

Checks an attachment being deleted to see if it’s a header or background image.

  | 
| [header_image()](https://developer.wordpress.org/reference/functions/header_image/)`wp-includes/theme.php` |

Displays header image URL.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 5 content](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#comment-content-1015)
 2.    [Jesse Dyck](https://profiles.wordpress.org/jessedyck/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_header_image/#comment-1015)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_header_image%2F%23comment-1015)
     Vote results for this note: 8[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_header_image%2F%23comment-1015)
 4.  Before using this, check out [get_header_image_tag()](https://developer.wordpress.org/reference/functions/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.
 5.  [https://developer.wordpress.org/reference/functions/get_header_image_tag/](https://developer.wordpress.org/reference/functions/get_header_image_tag/)
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_header_image%2F%3Freplytocom%3D1015%23feedback-editor-1015)
 7.   [Skip to note 6 content](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#comment-content-2515)
 8.    [Muhammad Ijaz Anjum](https://profiles.wordpress.org/id4ijaz/)  [  9 years ago  ](https://developer.wordpress.org/reference/functions/get_header_image/#comment-2515)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_header_image%2F%23comment-2515)
     Vote results for this note: 4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_header_image%2F%23comment-2515)
 10.     ```php
         the_custom_header_markup(); 
         ```
     
 11. can be use in place of
      [html] <img alt="" src="<?php [header_image()](https://developer.wordpress.org/reference/functions/header_image/);?
     >" width="<?php echo [get_custom_header()](https://developer.wordpress.org/reference/functions/get_custom_header/)-
     >width; ?>" height="<?php echo [get_custom_header()](https://developer.wordpress.org/reference/functions/get_custom_header/)-
     >height; ?>">[/html]
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_header_image%2F%3Freplytocom%3D2515%23feedback-editor-2515)
 13.  [Skip to note 7 content](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#comment-content-2356)
 14.   [Anthony Hortin](https://profiles.wordpress.org/ahortin/)  [  9 years ago  ](https://developer.wordpress.org/reference/functions/get_header_image/#comment-2356)
 15. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_header_image%2F%23comment-2356)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_header_image%2F%23comment-2356)
 16. Related:
 17. [header_image](https://developer.wordpress.org/reference/functions/header_image/)
     
     [has_header_image](https://developer.wordpress.org/reference/functions/has_header_image/)
 18.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_header_image%2F%3Freplytocom%3D2356%23feedback-editor-2356)
 19.  [Skip to note 8 content](https://developer.wordpress.org/reference/functions/get_header_image/?output_format=md#comment-content-679)
 20.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_header_image/#comment-679)
 21. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_header_image%2F%23comment-679)
     Vote results for this note: -1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_header_image%2F%23comment-679)
 22. **Example**
 23.     ```php
         <img src="<?php echo esc_url( get_header_image() ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'title' ) ) ); ?>" />
         ```
     
 24.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_header_image%2F%3Freplytocom%3D679%23feedback-editor-679)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_header_image%2F)
before being able to contribute a note or feedback.