简体   繁体   English

为整个网站的缺失替代图片添加替代文字

[英]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.我想为我的 wordpress 网站中所有图像的缺失 alt 添加替代文本。 I found the following code and added to my function.php.我找到了以下代码并添加到我的 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您可以添加插件 Bulk Auto Image Alt Text(Alt 标签,Alt 属性)优化(图像 SEO)+ Woocommerce 它将批量添加 alt 文本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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