WordPress - Overwriting/Filtering get_header_image_tag


Staff member
I want to change the output for get_header_image_tag function to output the exact HTML that I want to. I also want to be able to add data to the output such as new srcset that have not been covered...

I have tried to use <a href="https://developer.wordpress.org/reference/hooks/get_header_image_tag/" rel="nofollow">apply_filters get_header_image_tag</a> to test it out but couldn't get it to work:

apply_filters('get_header_image_tag', "&lt;img src&gt;", get_custom_header(), ['url' =&gt; 'test']);
echo get_header_image_tag();

I am pretty convinced that my understanding of how the apply_filters works might be the issue there... I've been reading about it but I can't get my head around the parameters. Most of the examples I have found online used only a hook and a single value.

The way I understood it, I want the output to be
&lt;img src=url&gt;
by using the data in
and replacing the URL attribute with 'test'.

However, what is being outputted is the default get_header_image_tag. I've also tried to directly echo the apply_filters:

echo apply_filters('get_header_image_tag', "&lt;img src&gt;", get_custom_header(), ['url' =&gt; 'test']);

But then, only
&lt;img src&gt;
is outputted...