WordPress - Overwriting/Filtering get_header_image_tag

admin

Administrator
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:

Code:
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
Code:
&lt;img src=url&gt;
by using the data in
Code:
get_custom_header()
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:

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

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