I would like to add alt text for missing alt of all images in my wordpress website. I found the following code and added to my function.php. It not work. So could you please check for me what I need to do?
Thanks
function add_alt_to_images_if_missing( $attr, $attachment = null ) {
if($attr['alt']==''){
$attr['alt']=trim( strip_tags( $attachment->post_title ) );
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes','add_alt_to_images_if_missing', 10, 2 );
My Answer:
>post_title ) );_}_return $attr;_}_add_filter( 'wp_get_attachment_image_attributes', 'add_alt_to_images_if_missing', 10, 2 );
Rate this post
4 of 5 based on 3526 votesComments