How to add alt tags to WooCommerce product images

TIPS

May 21, 2019 | WooCommerce Tips | 0 comments

Add the function below to your child theme functions.php file. [php] // adding alt tags to product 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; } [/php]

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

More Tips

Ad - Web Hosting from SiteGround - Crafted for easy site management. Click to learn more.

Cloudways Hosting

WPEngine Hosting

Pressable Hosting

AccuWeb Hosting

Ask the Divi Guy a Question

"*" indicates required fields