Category Image Banner Above Products
Displays the image you set on a product category as a wide banner at the top of that category's page, which many themes do not show.
Opens WPIDE on
Code
if ( is_product_category() ) {
$term = get_queried_object();
$image_id = (int) get_term_meta( $term->term_id, 'thumbnail_id', true );
if ( $image_id ) {
echo '<div class="wpide-category-banner" style="margin:0 0 24px;border-radius:8px;overflow:hidden;">';
echo wp_get_attachment_image( $image_id, 'full', false, array(
'style' => 'display:block;width:100%;height:auto;max-height:320px;object-fit:cover;',
'alt' => $term->name,
'loading' => 'eager',
) );
echo '</div>';
}
}
Notes
Set the image in Products > Categories > Edit category > Thumbnail. Categories without an image show nothing.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.