Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ben-heath/5f7031a4ff393e5db9b41ec0df3446cc to your computer and use it in GitHub Desktop.
Save ben-heath/5f7031a4ff393e5db9b41ec0df3446cc to your computer and use it in GitHub Desktop.
Custom WooCommerce Shop Loop Product Thumbnail and Title
<?php
/**
* Check if WooCommerce is active
**/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
// remove product thumbnail and title from the shop loop
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
// add the product thumbnail and title back in with custom structure
add_action( 'woocommerce_before_shop_loop_item_title', 'sls_woocommerce_template_loop_product_thumbnail', 10 );
function sls_woocommerce_template_loop_product_thumbnail() {
echo '<a class="thumbnail" title="'.get_the_title().'" href="'. get_the_permalink() . '">'.woocommerce_get_product_thumbnail().'</a>';
echo '<h3><a href="'.get_the_permalink().'">'.get_the_title().'</a></h3>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment