On the product detail page of the template I'm using I've noticed the thumbnail images don't include an alt attribute. The code is implemented as alt="".

Looking at the product image proper (the one marked default in the admin for the product) I can see the alt attribute is determined by alt="'.$this->htmlEscape($this->getImageLabel()).'"

What's interesting is it seems this is pulled off the product (from app/code/core/Mage/Catalog/Block/Product/Abstract.php)

public function getImageLabel($product = null, $mediaAttributeCode = 'image')
    if (is_null($product)) {
        $product = $this->getProduct();

    $label = $product->getData($mediaAttributeCode . '_label');
    if (empty($label)) {
        $label = $product->getName();

    return $label;

I know the label for each image is in the system, because if I change the default image of the product, the alt attribute of the main product image is now reflective of the newly assigned image. I just need to understand how to fetch the attribute off the image object rather than the product object.

1 Answer 1


It turned out to be trivial when I looked into it. The $_image variable is an instance of VarienObject with a label property, so it's just a matter of calling $_image->getLabel().

Here's an abridged section of the final code

foreach ($this->getGalleryImages() as $_image): ?>
    <a href="#" ....>
        <img alt="<?=$_image->getLabel()?> ...

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.