Wordpress 如何控制WooCommerce中变量$image的HTML输出

Wordpress 如何控制WooCommerce中变量$image的HTML输出,wordpress,woocommerce,thumbnails,Wordpress,Woocommerce,Thumbnails,我正在使用WooCommerce,在我的单一产品页面上,我有一个产品图片的概述。我使用product-thumbnails.php模板调用图像,但结果与CSS冲突,因为$image的输出在HTML中添加了像素大小 现在: 期望的: <img src="http://example.com/image.jpg"> 如何更改$image的输出?HTML5 blank有一个很好的例子,可以回答您的一些问题,请看一看,特别是其中的行和操作: add_filter('post_thu

我正在使用WooCommerce,在我的单一产品页面上,我有一个产品图片的概述。我使用product-thumbnails.php模板调用图像,但结果与CSS冲突,因为$image的输出在HTML中添加了像素大小

现在:


期望的:

<img src="http://example.com/image.jpg">


如何更改$image的输出?

HTML5 blank有一个很好的例子,可以回答您的一些问题,请看一看,特别是其中的行和操作:

add_filter('post_thumbnail_html', 'remove_width_attribute', 10 );

function remove_width_attribute( $html ) {
   $html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
   return $html;
}
要专门针对您所引用的模板,您可以专门挂接到该过滤器(
woocommerce\u single\u product\u image\u thumbnail\u html
)中,并对该函数进行如下修改:

add_action('woocommerce_single_product_image_thumbnail_html','remove_single_product_image_attrs',10,4);

function remove_single_product_image_attrs( $image_html, $attachment_id, $post, $image_class ){
    return preg_replace( '/(width|height)="\d*"\s/', "", $image_html );
}

HTML5 Blank有一个很好的例子,可以回答您的一些问题,看看它所连接的行和操作:

add_filter('post_thumbnail_html', 'remove_width_attribute', 10 );

function remove_width_attribute( $html ) {
   $html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
   return $html;
}
要专门针对您所引用的模板,您可以专门挂接到该过滤器(
woocommerce\u single\u product\u image\u thumbnail\u html
)中,并对该函数进行如下修改:

add_action('woocommerce_single_product_image_thumbnail_html','remove_single_product_image_attrs',10,4);

function remove_single_product_image_attrs( $image_html, $attachment_id, $post, $image_class ){
    return preg_replace( '/(width|height)="\d*"\s/', "", $image_html );
}

这确实很有效。我以前确实试过拧那个钩子,但我的头绕不过去。有什么想法可以找到更多关于这个的信息吗?@user3782713你想知道更多关于什么的信息吗?函数()之间的所有内容。这些变量在哪里描述,以及如何像您使用
preg\u replace
那样修改它们。这确实非常有效。我以前确实试过拧那个钩子,但我的头绕不过去。有什么想法可以找到更多关于这个的信息吗?@user3782713你想知道更多关于什么的信息吗?函数()之间的所有内容。这些变量在哪里描述,以及如何像使用
preg\u replace
那样修改它们。