[wp-trac] [WordPress Trac] #38942: New filter for header image tag attributes

WordPress Trac noreply at wordpress.org
Thu Oct 21 06:09:07 UTC 2021


#38942: New filter for header image tag attributes
-------------------------+-----------------------
 Reporter:  junaidbhura  |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  5.9
Component:  Themes       |     Version:  4.7
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:  template
-------------------------+-----------------------
Changes (by sabernhardt):

 * milestone:  Awaiting Review => 5.9


Comment:

 With 34644.patch, @sebastian.pisula made another version of this filter to
 add a class or similar attribute. However, I like how
 [attachment:"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 );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/38942#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list