Using WordPress ‘get_header_image_tag()’ PHP function

The get_header_image_tag() WordPress PHP function creates image tag markup for a custom header image.

Usage

echo get_header_image_tag(array('class' => 'my-custom-header'));

Parameters

  • $attr (array) – Optional. Additional attributes for the image tag. Can be used to override the default attributes. Default: array().

More information

See WordPress Developer Resources: get_header_image_tag

Examples

Display header image with a custom class

Add a custom class to the header image using the get_header_image_tag() function.

echo get_header_image_tag(array('class' => 'custom-header-image'));

Add custom alt text to header image

Use the get_header_image_tag() function to add a custom alt text to the header image.

echo get_header_image_tag(array('alt' => 'Your Custom Alt Text'));

Add multiple attributes to header image

Add multiple attributes like custom class, alt text, and width to the header image using the get_header_image_tag() function.

echo get_header_image_tag(array(
    'class' => 'custom-header-image',
    'alt' => 'Your Custom Alt Text',
    'width' => '100%'
));

Modify existing attribute in header image

Modify an existing attribute like width of the header image using the get_header_image_tag() function.

echo get_header_image_tag(array('width' => '80%'));

Display header image without any custom attributes

Display the header image without any custom attributes using the get_header_image_tag() function.

echo get_header_image_tag();