问题描述
我正在尝试删除单一产品页面上灯箱功能中图片上方显示的图片文件名。
I'm trying to remove the image filename that appears above the image in the lightbox functionality on the single-product page.
我的图片有一个可怕的命名结构,很容易让用户分心看到IMG_1234.JPG。
My images have a terrible naming structure and it is very distracting to the user to see "IMG_1234.JPG".
WooCommerce中是否有设置,允许我将其打开和关闭?
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?
提前感谢...
推荐答案
如果您使用任何woocommerce兼容模板,那么你会在模板文件夹中找到一个名为woocommerce的目录。
If you use any woocommerce compatible template then you'll find a directory named "woocommerce" in your template folder.
如果您找不到,则会是 wp-contents / plugins / woocommerce / templates
目录。在这种情况下,您的主题不会覆盖默认布局。然后你需要找到模板(或woocommerce)/single-product/product-image.php
文件。在第21行你应该找到如下 -
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() ) );
在该行添加// infront(注释掉),如下 - 。
add // infront of that line (comment that out) as follows-.
// $image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) );
现在搜索 rel =prettyPhoto
在中删除 rel =prettyPhoto
的 title =%s
在上一个文件夹中再次找到 product-thumbnailails.php
。在40左右,你会看到如下的一些东西 -
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 ) );
注释,添加两个正斜杠(//)就像上一个。
现在再次在第42行搜索 prettyPhoto [product-gallery]
,当你找到 title =%s
附近,并像之前一样删除。
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.
这下面的脚本在你的header.php文件或任何你可能找到合适 -
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>
这篇关于Woocommerce - 删除产品图片库(lightbox)上的图片文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!