[wp-trac] [WordPress Trac] #28861: No easy way to get alt text of custom header image

WordPress Trac noreply at wordpress.org
Mon Jul 14 16:47:13 UTC 2014


#28861: No easy way to get alt text of custom header image
--------------------------+------------------------------
 Reporter:  henry.wright  |       Owner:
     Type:  enhancement   |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Themes        |     Version:  3.4
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by henry.wright):

 If it's any use, this is the function I'm using (adapted from
 [http://wordpress.stackexchange.com/a/151864/22599/ here]).

 {{{
 function get_custom_header_image_alt() {
     $attachment_id = 0;
     if ( is_random_header_image() ) {
         $header_url = get_header_image();
         if ( $header_url ) {
             foreach ( get_uploaded_header_images() as $header ) {
                 if ( $header['url'] == $header_url ) {
                     $attachment_id = $header['attachment_id'];
                     break;
                 }
             }
         }
     } else {
         $attachment_id = get_custom_header()->attachment_id;
     }
     if ( $attachment_id ) {
         $alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt',
 true );
         if ( ! $alt )
             $alt = '';
     } else {
         $alt = '';
     }
     return $alt;
 }
 }}}

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


More information about the wp-trac mailing list