简体   繁体   中英

Add alt text for missing alt images for whole website

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 );

You can add plugin Bulk Auto Image Alt Text (Alt tag, Alt attribute) optimization (image SEO) + Woocommerce it will add alt text in bulk

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM