0

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?

B_etta
  • 117
  • 2
  • 17

1 Answers1

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

I followed How to display Woocommerce Category image? and set echo "'{$image}'";
instead of echo "<img src='{$image}' alt='' width='762' height='365' />";

Community
  • 1
  • 1
B_etta
  • 117
  • 2
  • 17