Hello,
I apologize for the issue you are facing with the %parent_category%
variable not working as expected with WooCommerce categories. Unfortunately, the %parent_category%
variable is not supported in the context of WooCommerce categories.
To achieve your desired title format, you might need to manually set the title or use a different approach to include the parent category in your titles.
If you have any specific technical issues or need further assistance, please reply to this ticket with your site URL, and a human agent from the Rank Math Support team will assist you further.
Thank you for raising this concern!
Hello,
Thank you for your query and we are so sorry about the trouble this must have caused.
The parent category is not available in our plugin so it is expected that it is not working on your website.
However, we can create custom variable function for it to work. You may use the following code:
add_action('rank_math/vars/register_extra_replacements', function () {
rank_math_register_var_replacement(
'parent_category',
[
'name' => esc_html__('Parent Category Name', 'rank-math'),
'description' => esc_html__('Displays the parent category name of the current term.', 'rank-math'),
'variable' => 'parent_category',
'example' => 'Example Parent Category',
],
'parent_category_call_back'
);
});
function parent_category_call_back() {
$term = get_queried_object();
if ($term && isset($term->term_id) && isset($term->taxonomy)) {
if ($term->parent != 0) {
$parent_term = get_term($term->parent, $term->taxonomy);
return $parent_term ? esc_html($parent_term->name) : '';
}
}
return '';
}
You may refer to this guide on how to add filters to your website: https://rankmath.com/kb/wordpress-hooks-actions-filters/
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.