Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have downloaded a wordpress theme called livepuse, and unfortunately the alt tags are not showing on portfolio pages for my images. The website is as follows: http://vitul3ddesigns.com/project/listed-buildings/

the code snippet from the theme is as follows:

<div class="thumbs">
                                                <?php
                                                    foreach ($images as $att) {
                                                        // get image's source based on size, can be 'thumbnail', 'medium', 'large', 'full' or registed post thumbnails sizes
                                                        $src = wp_get_attachment_image_src($att, 'full');
                                                        $src = $src[0];?>
                                                                <a href="">
                                                                <img src="
                                                                <?php if($rscript == 'TimThumb'){ ?>
                                                                    <?php bloginfo('template_directory');?>/scripts/timthumb.php?src=<?php echo $src; ?>&amp;w=70&amp;h=40&amp;a=t&amp;q=95&amp;zc=1 
                                                                <?php } elseif($rscript == 'PHP Thumb'){ ?>
                                                                    <?php bloginfo('template_directory');?>/phpThumb/phpThumb.php?src=<?php echo $src; ?>&amp;w=70&amp;h=40&amp;q=95&amp;zc=1 
                                                                <?php } elseif($rscript == 'Disable Resize Script'){ ?>
                                                                    <?php echo $attachment[0];?>
                                                                <?php } else{?>
                                                                    <?php bloginfo('template_directory');?>/scripts/timthumb.php?src=<?php echo $src; ?>&amp;w=70&amp;h=40&amp;a=t&amp;q=95&amp;zc=1 
                                                                <?php }?>

                                                                " alt=""/>
                                                </a>
                            <?php
                                                    }
                                                    ?>
                                    </div>

Thanks for your help in advance...

share|improve this question
add comment

3 Answers

alt="<?php echo get_post_meta($att, '_wp_attachment_image_alt', true); ?>"

This should do the trick. The alt of an image is set in a custom meta field called "_wp_attachment_image_alt".

share|improve this answer
    
Cheers Rob, I tried the code that you added above to no avail. Any other ideas? –  Luke Tulley Jan 20 '12 at 11:41
    
Rob, I managed to get that to work in the end. Please could you just clarify, if I wanted to add the image titles would I just add in the following title="<?php echo get_post_meta($att, '_wp_attachment_image_title', true); ?>" Thanks Again –  Luke Tulley Jan 20 '12 at 11:53
    
title="<?php echo get_the_title($att); ?>" will get you the title of the image. –  Rob Vermeer Jan 20 '12 at 12:41
    
Perfect result. Thank you soo much for your help!! –  Luke Tulley Jan 20 '12 at 12:53
    
No problem :-) One thing you can do for the community here is accept an answer if you get the answer you wanted. Otherwise the question keeps floating around as unanswered. Read about it in the FAQ (wordpress.stackexchange.com/faq#howtoask) –  Rob Vermeer Jan 20 '12 at 13:05
add comment

@Luke Tulley

From your code it seems the alt tags are there but are empty, there are a number of ways you can define them, a simple way is to use the post title:

 alt="<?php the_title(); ?>"

Or alternativly use a custom field and use the get_post_meta function.

http://codex.wordpress.org/Function_Reference/get_post_meta

New code:

<?php
foreach ($images as $att) {
    $alttag = get_post_meta($post->ID, 'Alt', true);
    $src = wp_get_attachment_image_src($att, 'full');
    $src = $src[0];?>
    <a href="">
    <img src="
    <?php if($rscript == 'TimThumb'){ ?>
    <?php bloginfo('template_directory');?>/scripts/timthumb.php?src=<?php echo $src; ?>&amp;w=70&amp;h=40&amp;a=t&amp;q=95&amp;zc=1 
    <?php } elseif($rscript == 'PHP Thumb'){ ?>
    <?php bloginfo('template_directory');?>/phpThumb/phpThumb.php?src=<?php echo $src; ?>&amp;w=70&amp;h=40&amp;q=95&amp;zc=1 
    <?php } elseif($rscript == 'Disable Resize Script'){ ?>
    <?php echo $attachment[0];?>
    <?php } else{?>
    <?php bloginfo('template_directory');?>/scripts/timthumb.php?src=<?php echo $src; ?>&amp;w=70&amp;h=40&amp;a=t&amp;q=95&amp;zc=1 
    <?php }?>
    " alt="<?php echo $alttag; ?>"/>
    </a>
<?php } ?>

Now in your new post in wordpress use 'Alt' as the name of your custom field then enter the desired value for your alt tag.

Can't see the custom fields box in the new post area? Under the screen options you can check to display them.

share|improve this answer
    
Matt, thanks for the prompt response. I have previously tried using the alt="<?php the_title(); ?>", but as you mention in returns the post title. I really need to pull in the alt attributes attached to each image that I uploaded to wordpress for seo purposes. I am new to coding and don't understand if / how the get_post_meta function would work differently to the post title solution. Thanks in advance –  Luke Tulley Jan 20 '12 at 1:38
    
Try the new code in my original post. –  Shoebox Jan 20 '12 at 1:54
    
Matt, This only adds the post page alt tag, my problem is that my site is a protfolio site and I'm trying to use the alt tags for each individual image. Is this possible? –  Luke Tulley Jan 20 '12 at 11:12
    
Matt, as mentioned above, I managed to get this method to work as per Robs post, I can see that they are obviously very much the same in methodology, please could you clarify now what argument I would use to call the title attribute from the images. once again thank you soo much for your help –  Luke Tulley Jan 20 '12 at 12:02
add comment

Change the image return type to "Image Object" (custom field type option).

Then do this:

<?php
    $image = get_field('image');
?>
<p>The url is: <?php echo $image['url']; ?>, the title is <?php echo $image['title']; ?> and the alt is: <?php echo $image['alt']; ?></p>

You will need to replace field_type('image') accordingly as well.

See here: http://support.advancedcustomfields.com/discussion/3794/how-to-get-image-url-alt-title-/p1

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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