Woocommerce - Remove image filename on product image gallery (lightbox) [closed]

亡梦爱人 提交于 2020-02-02 21:10:13

问题


I'm trying to remove the image filename that appears above the image in the lightbox functionality on the single-product page.

My images have a terrible naming structure and it is very distracting to the user to see "IMG_1234.JPG".

Is there a setting in WooCommerce that will allow me to toggle this on and off? Or will I need to change the file by adding/removing code?

Thanks in advance...


回答1:


If you use any woocommerce compatible template then you'll find a directory named "woocommerce" in your template folder.

If you can't find it then it'll be the wp-contents/plugins/woocommerce/templates directory. In that case your theme doesn't overwrite the default layout. Then you need to find templates(or woocommerce)/single-product/product-image.php file. Around line 21 you should find something as following-

$image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) );

add // infront of that line (comment that out) as follows-.

// $image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) );

Now search for something rel="prettyPhoto' around in line 31. Remove title="%s" from that line where you find rel="prettyPhoto'.

Again find product-thumbnails.php in the same folder of the previous one. In around 40 you'll see something as follows like before-

$image_title = esc_attr( get_the_title( $attachment_id ) );

Comment this out adding two forward slashes(//) just like the previous one. Now again in around line 42 search for something prettyPhoto[product-gallery] and when you find it look for title="%s" nearby and remove it like before.

This will remove the title form the lightbox picture viewer.

Instead of all these works you can simply use this following script inside your header.php file or anywhere you may find suitable-

<script>
    jQuery(document).ready(function(){
        jQuery('a[rel*="prettyPhoto"]').attr('title','').find('img').attr('alt','');
    });
</script>


来源:https://stackoverflow.com/questions/19599580/woocommerce-remove-image-filename-on-product-image-gallery-lightbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!