Support

Account

Home Forums Front-end Issues can no longer get ALT + Title for images Reply To: can no longer get ALT + Title for images

  • After banging away on various solutions, I finally guessed that simply rewriting the array could solve it. Also found some better methods for getting the ALT and TITLE values.

    Here’s my code for responsive SEO images with ALT and TITLE tags!

    <?php
    	$image = get_sub_field('photo') ;
    	$size = '2048x2048'; 
    	$alt = get_post_meta($image, '_wp_attachment_image_alt', TRUE);
    	$img_title = get_the_title($image);						
    ;?>
    
     <?php if( $image ) {
    		echo wp_get_attachment_image( $image, $size, array('alt'=>$alt), array('title'=>$img_title));
    	};
    ?>