After doing some research I found out that image titles and alt matters a lot for SEO and changing each image title and alt will take too long.
I found this code here but it did not affect the current images.
add_filter('wp_get_attachment_image_attributes', 'change_attachement_image_attributes', 20, 2);
function change_attachement_image_attributes( $attr, $attachment ){
// Get post parent
$parent = get_post_field( 'post_parent', $attachment);
// Get post type to check if it's product
$type = get_post_field( 'post_type', $parent);
if( $type != 'product' ){
return $attr;
}
/// Get title
$title = get_post_field( 'post_title', $parent);
$attr['alt'] = $title;
$attr['title'] = $title;
return $attr;
}
2
Answers
You can try
woocommerce_gallery_image_html_attachment_image_params
filter for the customization. Check following example. It fetches the product title and assigns it to thealt
andtitle
attribute of the image. Note: This only works in product single page.Log in to your Phpmyadmin, select your database and run this query to update images titles:
… and this SQL query to update images alts: