Hi
I need some help with the woocommerce page titles. At the moment the title bar shows the product sub category name. Which is great.
e.g. Page title is “Smooth Leather”
But what I would like to do is also display the the parent category name
e.g Clean: Smooth Leather
(Parent Category is “Clean” Sub category is “Smooth Leather”)
Is there a way to do this?
Many Thanks
Regards
Colin
Hi waveseven!
Thank you for using Enfold.
Are you referring to the theme’s default title container? Please add this filter in the functions.php file.
add_filter('avf_title_args','avf_title_args_mod', 10, 4);
function avf_title_args_mod($args)
{
global $wp_query;
$id = $wp_query->get_queried_object_id();
$parent = get_category_parents( $id );
$parent = explode("/", $parent);
if(is_tax('product_cat') && $parent[0] != $args['title'])
{
$args['title'] = $parent[0] . ': ' . $args['title'];
}
return $args;
}
Best regards,
Ismael
Hi Ismael
Thanks for your reply. That is BRILLIANT !!! Just what I needed.
I LOVE THIS THEME !!!
Many Thanks
Regards
Colin
Hi Ismael
I’ve added in the code to the functions.php file and it works great. However, when I click on a Category from the menu that doesn’t have a subcategory it displays the Category name twice.
e.g Outdoor Range: Outdoor Range (see link in private content field)
Is there a way to fix this?
Many Thanks
Regards
Colin
Hi!
Thank you for the update. We adjusted the code a bit. Please try it again.
Regards,
Ismael
Hi Ismael
The adjusted code works perfectly. Thanks again for all your help.
Regards
Colin
Hi Colin,
Glad we could help :-)
Please let us know if you should need any further help on the topic or if we can close it.
Best regards,
Rikard
Hi Rikard
Everything seems to be working as we wanted it, thank you. The ticket can be closed.
Many Thanks
Regards
Colin