2

I'm trying to add the category name next to the product name on my woocommerce page. I would like to displays it because of SEO reasons, so that Google knows that this product belongs to this category.

My code looks like this at the moment

 the_title( '<h1 class="product_title entry-title">', '</h1>  <?php echo wc_get_product_category_list($product->get_id()) ?>'  );

I tried to get it done by adding

<?php echo wc_get_product_category_list($product->get_id()) ?>

but there is no category name and dev consolse etc also shows no errors.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
p_e_88
  • 1,029
  • 11
  • 24

1 Answers1

1

Instead try to replace your code with the following:

the_title( '<h1 class="product_title entry-title">', '</h1>' ); 
$terms = wp_get_post_terms( get_the_id(), 'product_cat' );
$term  = reset($terms);
echo $term->name;

It should work.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Hi, by adding this code it's hiding the product name and only shows the categories, as a breadcrumb, it should be only Product name Active Category. https://s16.directupload.net/images/190318/66jthrsf.png – p_e_88 Mar 18 '19 at 16:05
  • @p_e_88 Made an update that will display only the first product category… – LoicTheAztec Mar 18 '19 at 16:49