#38942 closed enhancement (fixed)
New filter for header image tag attributes
Reported by: | junaidbhura | Owned by: | johnjamesjacoby |
---|---|---|---|
Milestone: | 5.9 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | Themes | Keywords: | has-patch has-dev-note |
Focuses: | template | Cc: |
Description
There is currently no way to filter the attributes of the header image tag before it is used to build the header image tag HTML in the get_header_image_tag() function.
I've attached a diff to solve this problem by adding a new 'get_header_image_tag_attributes' filter.
Attachments (2)
Change History (20)
This ticket was mentioned in Slack in #core by junaidbhura. View the logs.
8 years ago
This ticket was mentioned in Slack in #core-themes by junaidbhura. View the logs.
8 years ago
#5
in reply to:
↑ 4
@
8 years ago
Replying to obenland:
I'm not sure a filter is really needed here since the function accepts an array of attributes that override any defaults. Am I missing something?
The idea is to have this work similar to wp_get_attachment_image_attributes
. There is currently no way to modify the header image's attributes like a normal attachment image.
There is a get_header_image_tag
filter, but that is applied after the image's HTML has already been built.
This ticket was mentioned in Slack in #core-themes by junaidbhura. View the logs.
8 years ago
This ticket was mentioned in Slack in #themereview by joyously. View the logs.
7 years ago
#11
@
3 years ago
- Milestone changed from Awaiting Review to 5.9
With 34644.patch, @sebastian.pisula made another version of this filter to add a class or similar attribute. However, I like how 38942.diff includes the $header
argument.
I tried these two implementations:
function edit_header_alt_with_url( $attr, $header ) { if ( '.jpg' === substr( $header->url, -4 ) ) { $attr['alt'] = 'new alt'; } return $attr; } add_filter( 'get_header_image_tag_attributes', 'edit_header_alt_with_url', 10, 2 ); function header_image_add_class( $attr ) { if ( isset( $attr['class'] ) ) { $attr['class'] .= ' special classes'; } else { $attr['class'] = 'special classes'; } return $attr; } add_filter( 'get_header_image_tag_attributes', 'header_image_add_class', 10, 1 );
This ticket was mentioned in Slack in #core by chaion07. View the logs.
3 years ago
@
3 years ago
Themes: Introduce get_header_image_tag_attributes
hook to filter the list of header image attributes.
#14
@
3 years ago
- Keywords commit added
Hi @junaidbhura! Thank you for reporting this. This ticket was discussed during a recent Bug-scrub session. Based on the feedback received we're adding the commit keyword. Having Unit Test would also be a good idea. Thanks!
Props to @costdev & @audrasjb
#16
@
3 years ago
- Owner set to johnjamesjacoby
- Resolution set to fixed
- Status changed from new to closed
In 51978:
#18
@
3 years ago
- Keywords has-dev-note added; commit needs-dev-note removed
Dev note published:
Theme-focused changes: Custom header image attributes
I'm not sure a filter is really needed here since the function accepts an array of attributes that override any defaults. Am I missing something?