I noticed in my wordpress/woocommerce setup that every time i add a tag to a product or a blog post. It adds that tag as a class into the listed item (Product/blog)
I also noticed it adds a class in the same place for every category i put these post items into.
How can i prevent wordpress and woocommerce from addings these tag and category names into my html markup as classes? As i do not need them and its creating a mess.
Thanks for any help! I could not locate a similar function anywhere.
I noticed in my wordpress/woocommerce setup that every time i add a tag to a product or a blog post. It adds that tag as a class into the listed item (Product/blog)
I also noticed it adds a class in the same place for every category i put these post items into.
How can i prevent wordpress and woocommerce from addings these tag and category names into my html markup as classes? As i do not need them and its creating a mess.
Thanks for any help! I could not locate a similar function anywhere.
You have to leverage the woocommerce wc_product_post_class
filter. The following code should do the trick.
function my_strip_tag_class( $classes ) {
global $post;
$product_tags = get_the_terms( $post->ID, 'product_tag' );
if( $product_tags ) foreach ( $product_tags as $tag ) {
$tag_index = array_search($tag, $classes);
if($tag_index !== false){
unset($classes[$tag_index]);
}
}
return $classes;
}
add_filter( 'wc_product_post_class', 'my_strip_tag_class' );
For WooCommerce 3.6.2+ try the woocommerce_post_class
filter:
add_filter('woocommerce_post_class', function($classes, $product) {
// remove whatever classes you want here...
return $classes;
}, 10, 2);