How to customize the title of the WooCommerce Product Archives based on the category?
To customize the title of the WooCommerce Product Archives based on the category, you can use a filter hook called “woocommerce_page_title“. By modifying this hook, you can change the text of the title according to the category and add the prefix “Here are” to every product category page. Here’s an example code snippet that you can add to your theme’s functions.php file:
function custom_woocommerce_page_title($page_title) {
if (is_product_category()) {
$category = single_term_title('', false); // Get the category name
$page_title = "Here are '$category'";
}
return $page_title;
}
add_filter('woocommerce_page_title', 'custom_woocommerce_page_title');
Make sure to replace “Here are” with your desired prefix. This code checks if the current page is a product category archive page using the is_product_category()
function. If it is, it retrieves the category name using single_term_title()
. Then, it modifies the page title by replacing the category name and adding the desired prefix. Finally, it returns the modified page title.
After adding this code, the title on the WooCommerce Product Archives pages will be customized according to the category, with the prefix “Here are” added.