Support

Account

Home Forums General Issues Getting the alt text instead of the image title

Solved

Getting the alt text instead of the image title

  • Hello I was working with this code.

    http://www.advancedcustomfields.com/resources/code-examples/#working-with%20images%20–%20id

    The image ID and instead of adding the image title inside the image alt attribute I was wondering if it’s possible to fetch for the real alt text instead of the image title.

    I thought this would work but it doesn’t.

    
    $slide_one = '<li><img src="'. $image_one[0] .'" alt="'. get_post_meta( $image_one, '_wp_attachment_image_alt', true ) .'" /></li>';
    

    If someone could look at this and tell me if i’m close here..
    🙂

  • Problem solved.. 🙂

    The variable $image_one doesn’t return the image ID anymore it should be get_field( ‘field_name’ ).

    Like this:

    
    $slide_one = '<li><img src="'. $image_one[0] .'" alt="'. get_post_meta( get_field('slide_image_one') ,'_wp_attachment_image_alt', true ) .'" /></li>';
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Getting the alt text instead of the image title’ is closed to new replies.