Show attached term names in product template

I want to show all attached terms in my product archive template. I know I can use query loop to query terms and select what I want. But I just want to show them in h1 heading, so I don’t want to use query loop. Any ideas?

Here is one of my products:

And I want my h1 heading to show like this:

you mean filtering/modifying the_title()

something like this.

function add_category_to_title($title, $id = null) {
    // Check if it's a single post view and the post ID is available
    if (is_single() && !is_null($id)) {
        // Get the categories of the post
        $categories = get_the_category($id);

        if (!empty($categories)) {
            $title .= ' - ' . $categories[0]->name;


    return $title;

// Add filter to modify the title
add_filter('the_title', 'add_category_to_title', 10, 2);

1 Like

Sorry for my late reply! I got another way from others. Share with you :smile:

1 Like