• Resolved David Gard

    (@duck_boy)


    Hey all,

    I have a template that displays an image attached to post. As part of the template I have the following code –

    $img = $post_images->first($post->ID)->url;
    <!-- Photo -->
    <div class="content_photo">
        <? if(!empty($img)){ ?><img src="<?=$img?>" width="166" height="" alt="<?php the_title(); ?>" title="<?php the_title(); ?>"/><? } ?>

    </div>

    However, as the media uploader assigns Alt text to the image, the ‘alt=’ portion is being ignored. Is there anyway to change this, as changing the properties of all images would be a nightmare plus it would make it a lot easier when uploading future images.

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Check this portion of your code: src="<?=$img?>" doesn’t look right to me.

    Thread Starter David Gard

    (@duck_boy)

    The image is displaying correctly, and the echo the_title(); is showing the correct wording, but the Alt text is not appearing. It seems that WordPress will only display this from the Alt Text field related to the image, which hasn’t been filled in and as there are lots of photos I don’t particularly want to! It’s that behaviour I’m looking to change.

    Thanks.

    did you look into the html code in the browser, to see what wordpress made with your code?

    could you post the rendered bit of html?

    or a link to your site where this image an be seen?

    do other image alt texts show in your browser?

    Thread Starter David Gard

    (@duck_boy)

    Hey alchymyth, thanks for the reply

    Here is the code from rendered HTML, which is showing the alt –

    <!-- Photo -->
    <img src="https://www.dynedrewett.com/wp-content/uploads/2009/10/Rebecca-Beresford.jpg" width="166" height="" alt="Rebecca Beresford" />

    And here is a Link to the site

    The company logo, top right, does display the alt text, but the image path is defined absolutly and the image hasn’t been uploaded through the media uploader, it’s just sat in a furniture folder.

    Thanks.

    seems to be a browser issue:
    (after all, when the code is rendered into html there is not trace left where the image or information came from)

    firefox3.5.8 does not show the alt text of the Rebecca image,
    – if i change that to a title text, it will show;
    – it shows the title text of the link on the company logo (‘Dyne Drewett LLP Solicitors home page’)
    and ignores the alt text of the image (‘Dyne Drewett Solicitors’);

    IE7 shows the alt text of the Rebecca image;
    and shows the alt text of the company logo image, it ignores the title text of the logo link.

    if the hover ‘text’ is important:
    maybe add both – title and alt – to the image and let the browser decide (it may look redundant if someone looks at the html in the browser, but ‘so what?’ …)

    i have not checked what a ‘text-only’ browser would make with the title or alt texts.

    Thread Starter David Gard

    (@duck_boy)

    Hey,

    Thanks for that. Have also added title="<?php the_title(); ?>" now and that is working in IE8 (Wasn’t with just alt), so looks to be problem solved. Wasn’t aware of that behaviour difference, but will know for the future.

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘alt=”<?php the_title(); ?>” not working’ is closed to new replies.