WordPress.org

Ready to get started?Download WordPress

Forums

Twenty Eleven
Twenty Eleven Adding Alt Text to Header Images (6 posts)

  1. leplant
    Member
    Posted 1 year ago #

    Can anyone show me how I can add the alt text from the media library to get that to display with the custom uploaded header images? I really need that to comply with disability accessibility requirements.

  2. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

    I'm not totally clear on what you are trying to do, but alt text generally does not display on the page unless the image is not available. So far as I am aware, accessibility just require that you have text in the alt field -- not that it's displayed on the page with the image. Alt text will be read by screen readers whether it's displayed on the page or not.

    If I'm misunderstanding or you're trying to do something else, can you explain further?

  3. leplant
    Member
    Posted 1 year ago #

    Hi Yogi!

    Thank you for writing:

    Could you look at the page source for: http://twentyelevendemo.wordpress.com/

    This is the HTML for the header image

    <img src="http://s2.wp.com/wp-content/themes/pub/twentyeleven/images/headers/trolley.jpg?m=1354160568g" width="1000" height="288" alt="" />

    The alt tag is empty on this site as it is on my site. Even though I have filled in the alt and description fields for the item in the media library.

    It would appear as if that alt field information is not being picked up by a query that gets the location of the image to display as the header.

    Do you see what I am talking about now?

    Thank you,

    leplant

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    edit header.php of Twenty Eleven;

    find this line:

    <img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />

    and expand it to:

    <?php $header_image_URL = get_header_image();
    					$header_image_att = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_content = '%s'",$header_image_URL ) );
    					$header_image_att_id = $header_image_att->ID;
    					$header_image_alt = get_post_meta($header_image_att_id, '_wp_attachment_image_alt', true); ?>
    					<img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="<?php echo $header_image_alt; ?>" />

    (most of the code is adapted from http://wordpress.org/support/topic/need-to-get-attachment-id-by-image-url?replies=20 )

    locate the respective images in the media library, and add the 'alternative text'; do the same for those posts and pages, where you have used the 'featured image'.

  5. lauraf1tz
    Member
    Posted 8 months ago #

    I'm having this same problem--I created a custom field for the alt text but can't figure out how to update my theme. I tried to find that line in my header.php but it doesnt exist. Any advice? Thanks!

  6. esmi
    Forum Moderator
    Posted 8 months ago #

    @lauraf1tz: As per the Forum Welcome, please post your own topic.

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic