I need to modify the default gallery code, I need the alt of the image to be the path to the big image. I've modified media.php like this:

function wp_get_attachment_image(...........
'alt'   => $src,
'title' => trim(strip_tags( $attachment->post_title )),

But now my alt is the path to the thumbnail of the image, I need the path to the big one, how can I do that?

Thanks for your time.

  • 2
    Which problem do you really want to solve? There is probably a better way than to annoy your screen reader users.
    – fuxia
    Feb 4, 2012 at 6:16

3 Answers 3


This should do the trick

add_filter('wp_get_attachment_image_attributes', 'change_alt_image', 10, 2);

function change_alt_image($attr, $attachment) {

$data_img = wp_get_attachment_image_src($attachment->ID, 'original', false);

    $attr['alt'] = esc_url($data_img[0]);

    return $attr;


Do you mean [gallery link="file"]
This should work if I understand your question.


I am using custom gallery script, in order to work, I need the default code that wordpress gallery generates to be changed so the image alt points the same as the big image url, so when it is clicked, the big image is loaded through the jquery gallery I am using. I managed to modify everything the way I need it but I cannot find what to do so I get the big image as alt value - alt="http://pathtofullsizeimage.com" ... All I managed to do is replace the alt value with $src, but it points to the thumbnail and I need the full image, my php knowledge is extremly poor and I need help to find out what to put instead of $src as value for the alt property in media.php or somewhere else.

Thanks for your time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.