Title: get_custom_header_markup
Published: December 7, 2016
Last modified: February 24, 2026

---

# get_custom_header_markup(): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_custom_header_markup/?output_format=md#description)
 * [Return](https://developer.wordpress.org/reference/functions/get_custom_header_markup/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_custom_header_markup/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_custom_header_markup/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_custom_header_markup/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_custom_header_markup/?output_format=md#wp--skip-link--target)

Retrieves the markup for a custom header.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_custom_header_markup/?output_format=md#description)󠁿

The container div will always be returned in the Customizer preview.

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

 string The markup for a custom header on success.

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

    ```php
    function get_custom_header_markup() {
    	if ( ! has_custom_header() && ! is_customize_preview() ) {
    		return '';
    	}

    	return sprintf(
    		'<div id="wp-custom-header" class="wp-custom-header">%s</div>',
    		get_header_image_tag()
    	);
    }
    ```

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

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

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

Checks whether a custom header is set or not.

  | 
| [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.

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

Whether the site is being previewed in the Customizer.

  |

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

Prints the markup for a custom header.

  |

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

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

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_custom_header_markup%2F)
before being able to contribute a note or feedback.