Remove tooltips on product image
-
Hello!
I have tried to remove the tooltips on the product image, but I can not seem to do it. It’s kind of silly to have a beautiful looking store, but when you hover the pictures you get “pcng29894.jpg” etc.
Have a nice day!
-
Are you talking about title tags? Link?
Hello! The site is in maintenance right now, but yes, if I remove the image title=”whatever” when I inspect the element, the tooltip does not show.
WordPress adds these to post thumbnails, if we’re talking about the same things. You can give images better titles in your media library.
Thank you for answering me.
So there is no solution to just remove the fact that when you hover over the image with the mouse on the product page, the image name shows? If I don’t want to have the text there at all?
Of course you can remove.
Just use thewoocommerce_single_product_image_thumbnail_htmlandwoocommerce_single_product_image_htmlfor it 🙂You can try something like http://wordpress.stackexchange.com/questions/64828/how-to-remove-title-attribute-from-gallery-links-and-images (not tested myself, its end of day here :))
Thank you for answering.
Mike, the [edit: information in the] link you posted sadly did not work.
Claudio, could you please explain a bit closer? Can I make a filter to put in my functions.php that fixes this for me? 🙂
Claudio, do you know?
Thanks!
Try this in functions.php to chop out the alt parameter.
add_filter ('woocommerce_single_product_image_html', 'my_function'); function my_function($html) { $start = stripos($html, 'alt="'); if ($start) { $end = stripos($html, '"', $start + 5); $html = substr($html, 0, $start - 1).substr($html, $end + 1); } return $html; }Hello again!
Thank you for the reply. The alt-tag was strippet out, but the tooltip still shows. I changed it to this:
add_filter ('woocommerce_single_product_image_html', 'my_function'); function my_function($html) { $start = stripos($html, 'title="'); if ($start) { $end = stripos($html, '"', $start + 5); $html = substr($html, 0, $start - 1).substr($html, $end + 1); } return $html; }But then nothing is stripped out. I probably have to strip out both the title and alt tags, but I don’t know how. Would appreciate the help!
Thanks!
“title” is 2 chars longer than “alt”, so alter “$start + 5” to “$start + 7”. See if that removes the title attribute. Sorry, not tested.
Thank you so much for your help and time, I truly appreciate it.
But sadly, that did not work 🙁 The script removes the alt tag with + 5, but not the title tag with + 7 and title=” in the correct field.
Any more suggestions? Would really appreciate it!
It sort-of worked. The enclosing a tag has a title attribute as well. That’s being removed but leaving the second title attribute in the img tag. So we need to remove two title attributes:
add_filter ('woocommerce_single_product_image_html', 'my_function'); function my_function($html) { $start = stripos($html, 'alt="'); if ($start) { $end = stripos($html, '"', $start + 5); $html = substr($html, 0, $start - 1).substr($html, $end + 1); } $start = stripos($html, 'title="'); // attribute in a tag if ($start) { $end = stripos($html, '"', $start + 7); $html = substr($html, 0, $start - 1).substr($html, $end + 1); } $start = stripos($html, 'title="'); // attribute in img tag if ($start) { $end = stripos($html, '"', $start + 7); $html = substr($html, 0, $start - 1).substr($html, $end + 1); } return $html; }Thank you for using so much of your time on this problem.
It sadly does not work. The alt tag is removed, the title tag is still there and the tooltip still shows.
Could you to post the markup for your product_image div. It’ll be something like this or post the link to a product page after you go live.
The topic ‘Remove tooltips on product image’ is closed to new replies.