This question already has an answer here:
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?
I followed How to display Woocommerce Category image? and set
echo "'{$image}'";
instead of
echo "<img src='{$image}' alt='' width='762' height='365' />";