如何将 woocommerce 类别的图像设置为类别标题的背景?

How can I set the Image of woocommerce category as the background of the category title?

我想将woocommerce类别图片设置为标题背景。

这是 archive-product 中的标题行。php

<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>

我写了

                <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>

我可以在浏览器编辑器中看到图片了!但是有些不对劲。我该如何解决?

<?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>

            <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 "'{$image}'";
}   
?>);" class="page-title"><?php woocommerce_page_title(); ?></h1>

我跟着How to display Woocommerce Category image?设置了echo "'{$image}'";
而不是 echo "<img src='{$image}' alt='' width='762' height='365' />";