1

I have a theme that uses TimThumb to generate thumbnail images on a gallery page. The problem is that image alt tags are not showing for each image on the main gallery pages, see here:

http://christinecraven.com/gallery/press

I've tried to generate the alt tag by adding a custom field in each post/ portfolio item, called "alt_tag" and then calling it in the category.php file in my theme:

$alttag = get_post_meta($post->ID, 'alt_tag', true);

<div class="imgHentry">
    <?php the_post_thumbnail( 'thumbnail' ); ?> alt="<?php echo get_post_meta($att, 'alt_tag', true); ?>" 
    <div class="linkIcon" style="width:150px; height:150px;">
        <a href="<?php the_permalink(); ?>" class="goto-icon" style="width:150px; height:150px;"></a>
    </div>
</div><!-- .imgHentry -->

I found on this forum a similar question: alt attributes not showing on pages

But unfortunately can't seem to cobble together a solution that works!

  • Where do you define $att? Also, the alt attribute needs to reside within the img tag, currently you are adding it outside of it. And the anchor is empty as well. – Johannes Pille Nov 28 '12 at 18:30
2

The following ought to be much closer to what you want to achieve:

<div class="imgHentry">
    <a href="<?php the_permalink(); ?>" class="goto-icon">
        <?php the_post_thumbnail(
            'thumbnail',
            array( 'alt' => get_post_meta( $post->ID, 'alt_tag', true ) )
       ); ?>
    </a>
</div>
| improve this answer | |
  • Sadly, it's not working. Shouldn't it be changing something though? I noticed in my original post, that yes I had made a typo in defining the $att, then tried to fix that, but that didn't seem to do anything. I wonder if I am in the correct template, but I can't imagine this isn't it. Any other ideas? Thank you! – user24198 Nov 28 '12 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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