Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@stuartduff
Created June 21, 2022 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartduff/35b88e4513c8ace1c539885d04784e4c to your computer and use it in GitHub Desktop.
Save stuartduff/35b88e4513c8ace1c539885d04784e4c to your computer and use it in GitHub Desktop.
Add WooCommerce product category image full width under the header of the Storefront theme.
/**
* Add WooCommerce product category image full width under the header of the Storefront theme.
*/
function woocommerce_category_image() {
if ( is_product_category() ){
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
echo '<img src="' . $image . '" alt="' . $cat->name . '" />';
}
}
}
add_action( 'storefront_before_content', 'woocommerce_category_image', 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment