Community Forums › Forums › Archived Forums › General Discussion › Remove Img Title Prettyphoto lightbox Woocommerce Product Page
Tagged: lightbox, prettyPhoto, WooCommerce
- This topic has 10 replies, 3 voices, and was last updated 7 years, 9 months ago by plentyvegan.
-
AuthorPosts
-
July 18, 2016 at 12:59 pm #189752plentyveganMember
I can't find anywhere where I would be able to remove the image title from the popup gallery on product pages: http://plentyvegan.com/product/22-days-nutrition-plant-protein-powder/
The code I can find in Woocommerce's theme is:
FOR THUMBNAILS:
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', sprintf( '%s', $image_link, $image_class, $image_caption, $image ), $attachment_id, $post->ID, $image_class );FOR SINGLE PRODUCT IMAGES:
http://plentyvegan.com/product/22-days-nutrition-plant-protein-powder/
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '%s', $props['url'], $props['caption'], $image ), $post->ID );July 21, 2016 at 10:23 am #189919ChristophMemberHi,
I don't see an image title in the lightbox, just the product title.
July 21, 2016 at 11:36 am #189939Genesis DeveloperMemberAdd this code in your child theme's functions.php.
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'gd_remove_title', 10, 4 ); function gd_remove_title( $image_html, $attachment_id, $post_ID, $image_class ) { $props = wc_get_product_attachment_props( $attachment_id ); $image_html = sprintf( '<a href="%s" class="%s" data-rel="prettyPhoto[product-gallery]">%s</a>', esc_url( $props['url'] ), esc_attr( $image_class ), wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ), 0, $props ) ); return $image_html; }
July 21, 2016 at 11:47 am #189943plentyveganMemberChristoph - I made the image titles the product titles. I removed the dashes. It looks like it's the product title but it's actually the image title that you are seeing.
I added the code above but nothing seems to have changed: http://plentyvegan.com/product/daiya-foods-cheezy-mac/
Thoughts?
Thanks.
July 21, 2016 at 12:29 pm #189948Genesis DeveloperMemberAdd this single line after the 3rd line (in above code).
$props['alt'] = '';
Otherwise you will target the wp_get_attachment_image_attributes filter and remove the alt.
July 21, 2016 at 12:34 pm #189949plentyveganMemberI added the line above. The image title is still showing up in the lightbox on the product page.
To recap, this is what I've added to the functions php file in the Divine Theme code:
//* Remove image title
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'gd_remove_title', 10, 4 );
function gd_remove_title( $image_html, $attachment_id, $post_ID, $image_class ) {
$props = wc_get_product_attachment_props( $attachment_id );
$props['alt'] = '';
$image_html = sprintf(
'%s',
esc_url( $props['url'] ),
esc_attr( $image_class ),
wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ), 0, $props )
);return $image_html;
}Thanks again for digging in with me.
July 21, 2016 at 12:47 pm #189952Genesis DeveloperMemberRemove the previous code and try this
add_filter('wp_get_attachment_image_attributes', 'divine_remove_image_alt' ); function divine_remove_image_alt( $atts) { if( is_singular('product') ) { unset( $atts['alt'] ); } return $atts; }
July 21, 2016 at 12:51 pm #189953plentyveganMemberHmmm - no dice.
July 21, 2016 at 1:01 pm #189956Genesis DeveloperMemberI shall check it tomorrow morning
July 21, 2016 at 1:17 pm #189957Genesis DeveloperMemberI just tested this code and it is working for me
add_filter('wp_get_attachment_image_attributes', 'divine_remove_image_alt' ); function divine_remove_image_alt( $atts) { if( is_singular('product') ) { $atts['title'] = ""; $atts['alt'] = ""; } return $atts; }
July 21, 2016 at 1:22 pm #189959plentyveganMemberSuccess!
Thanks so much!
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.