Quantcast
Channel: Automatically Match Woocommerce Product Images with Product Title - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Automatically Match Woocommerce Product Images with Product Title

$
0
0

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

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images