Support » Plugin: WooCommerce » Add Category Title to the Product_Title H1 on Product Page?

  • So I’ve used the variable %%ct_product_cat%% to add the category to the product on the page title, and would also like to see it in the “product_title” element on the product page itself. Right now it shows:

    <h1 class=”product_title entry-title”>%%title%%</h1>

    But I want it to output:

    <h1 class=”product_title entry-title”>%%ct_product_cat%% – %%title%%</h1>

    How can I do this? A function or hardcode edit on the page?

    Cheers!
    Ryan

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can use the_title filter in functions.php in theme folder.

    Thanks for the feedback! I’m close but am having one major issue. First, here is my code that successfully changes the H1.

    function change_product_title( $title, $id ) {
     		global $post;
     		$terms = get_the_terms( $post->ID, 'product_cat' );
     		//$category = get_the_category();
    		$firstCategory = $terms[0]->name;
     		echo "<!-- terms $firstCategory -->";
        if ( is_product() && in_the_loop() ) {
        	$category = get_the_category($post->ID);
        	$newtitle = "$firstCategory - $title";
            return $newtitle;
            //var_dump($category);
        }
    
        	return $title;
    	}
    	add_filter( 'the_title', 'change_product_title', 10, 2 );

    But, it is also adding the category to the “shop” level of the breadcrumbs. How do I tell it to not change the breadcrumbs?

    Cheers!
    Ryan

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add Category Title to the Product_Title H1 on Product Page?’ is closed to new replies.