This question already has an answer here:
- How to display Woocommerce Category image? 8 answers
I want to set the woocommerce category image as the title background.
This is the title line in archive-product.php
<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
I wrote
<h1 style="background: url(<?php if ( is_product_category() ){
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
echo "<img src='{$image}' alt='' width='762' height='365' />";
}
?>);" class="page-title"><?php woocommerce_page_title(); ?></h1>
I can see the image in the browser editor! But something is wrong. How could I resolve that?