Support » Fixing WordPress » How to fetch text from "alt. text" in images

  • Hi!

    I’m trying to fetch the text from what is written in the alternate text field of an image.

    What I try to achive with it is this: I have an image gallery on my page, when I click the images it opens them up in a lightbox. But instead, I will link each image to a post I have written about them. So I thought I could enter url to each post in the images alternate text field, and then have the code where the link is made get that text. This way I can enter a different url for each image.

    But I am a coding noob and I need help.

    Here is the code I try to alter:

    foreach($all_photo_arr as $photo)
    	$full_image_url = wp_get_attachment_image_src( $photo->ID, 'full' );
    	$small_image_url = wp_get_attachment_image_src( $photo->ID, 'large' );
    	echo '<img>';
    	echo '<src>'.$small_image_url[0].'</src>';
    	echo '<link>'.$full_image_url[0].'</link>';
    	echo '<title></title>';
    	echo '<caption></caption>';
    	echo '</img>';

    I guess that the string to the “alternate text” field has to be put in somehow in between the <link> tags.

    What do I put in between there to make it work? =)

Viewing 7 replies - 1 through 7 (of 7 total)
  • Why not simply make put the images inside link tags (a)??

    The purpose of the alt text is that it displays when the image cannot (for whatever reason) and, more importantly, the alt text is used by screen readers (as an accessibility feature) — for example, people who cannot see and depend on the alt text to describe the image. So using it for something else is not really a good idea in principle, and may in fact cause validation errors on the page.

    Check out this page. It’s for a student magazine. I want each image in the image gallery at the front page to link to the post where you can read the story instead of opening in a lightbox.

    Is this possible with your suggestion? If it is, what do I add in the above code to make it work?

    Link gets an error message…

    What theme or image gallery are you using? I would guess that there are some that would already do what you want.

    Ah ok: here’s the url:

    I use a theme called Core. They’ve made their own image gallery which is quite complex. That’s the problem 😛

    Since that’s a premium theme, you’ll need to go to the vendor for support — generally, commercial themes aren’t supported here. Good luck with it.

    Yes you are right.

    I was trying to make a “work-around” with it just fetching the text in the alternate text field, and then I enter the url there for every image.

    I’ll ask at the theme-support.

    But if you happen to know how to write the string/code to fetch the text from alternate text, feel free to share it =)

    No idea, and like I said, messing with “accessibility” features in HTML is not the way to go — see this:

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to fetch text from "alt. text" in images’ is closed to new replies.