Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 3 years ago

#28861 closed enhancement (duplicate)

No easy way to get alt text of custom header image

Reported by: henrywright's profile henry.wright Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4
Component: Themes Keywords:
Focuses: accessibility Cc:

Description (last modified by obenland)

get_custom_header()->width; and get_custom_header()->height; can be used to get the width and height of the custom header image but there seems to be no easy way to get the image's alt text.

The alt text is needed in cases where the custom header image is used to convey semantic content.

Change History (7)

#1 @obenland
10 years ago

  • Description modified (diff)
  • Version changed from 3.9.1 to 3.4

#2 @henry.wright
10 years ago

If it's any use, this is the function I'm using (adapted from 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;
}

#3 @obenland
10 years ago

It would be nice to get feedback from the accessibility group on that.

#4 @obenland
10 years ago

  • Focuses accessibility added

#5 @rianrietveld
10 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

This maybe a duplicate of ticket #15926: Add alt attribute support for Custom Header functionality.
Adding an alt="" if there is no alt given is, to my opinion, not a good idea, since the header image is in some themes also the link to the home page.
How to add a meaningful alt attribute is discussed in ticket #15926. And using the _wp_attachment_image_alt is a good one to add to the discussion.

#6 @sharonaustin
10 years ago

Strongly agree that adding an alt="" is a bad idea; my understanding is that with some screen readers, focus is lost if the alt atribute is empty. "If" people are relying on it to navigate home, then that is a problem.

What I don't know: If the header is wrapped in an <a> element, does the link function over-ride, or get over-ridden, by the the empty alt attribute?

For more background, see this:
".... The reason to use an empty ‘alt’ attribute is that this is a signal to the screen reader to skip over the image. When a screen reader comes across an image with an empty ‘alt’ attribute, it ignores the image: it’s as if the image was never there in the first place.."

http://www.userfocus.co.uk/articles/alt_text.html

#7 @SergeyBiryukov
10 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.