Hello,
We apologize for the inconvenience you’re experiencing with setting global titles and descriptions for product categories and subcategories. It seems that you are trying to set global titles and descriptions for product categories and subcategories using Rank Math.
The screenshot you’ve provided shows the “Product Categories” option, which applies the same global title and description template to all product categories. However, it seems that you are looking for a way to set different titles and descriptions for individual product subcategories.
To achieve this, you can set up individual titles and descriptions for each product category and subcategory by navigating to WordPress Dashboard > Rank Math > Titles & Meta > Product Categories. From there, you can set up individual titles and descriptions for each category and subcategory.
If you have any further questions or need assistance with this, please feel free to ask.
Thank you for bringing this to our attention.
Sources:
Rank Math ‘Titles and Meta’ Options and Settings
Hello,
Thank you for your patience.
Yes, the product categories in the Titles & Meta option affect all the categories including the parent and child.
However, you may use and customize these filters to modify the child categories meta title and description:
https://rankmath.com/kb/filters-hooks-api-developer/#change-the-title
https://rankmath.com/kb/filters-hooks-api-developer/#change-meta-description
Hope that helps
Please give me an example of how to use this?
/**
* Allow changing the meta description sentence from within the theme.
*
* @param string $description The description sentence.
*/
add_filter( ‘rank_math/frontend/description’, function( $description ) {
return $description;
});
Hello,
This filter hook allows you to modify the meta description sentence that Rank Math generates for your pages. The filter hook takes one parameter, $description
, which is the original meta description sentence. You can return a modified version of the $description
from the filter function.
For example, if you want to change the description of any product category (child or parent), you can use the following code:
add_filter( 'rank_math/frontend/description', function( $description ) {
// Check if the current page is a product category archive page
if ( is_product_category() ) {
// Get the product category object
$product_category = get_queried_object();
// Compare the product category slug or name with your desired sub-category
if ( $product_category->slug == 'clothing' || $product_category->name == 'Clothing' ) {
// Return a different description
return 'This is a special sub-category';
}
}
// Return the original description for other cases
return $description;
});
This code will change the SEO description of any product category. You can change the description to anything you want, or use other logic to modify the description.
You can learn more about the rank_math/frontend/description
filter hook and other Rank Math filter hooks from here.
I hope this helps you understand how to use the filter hook. If you have any further questions or need more assistance, please let us know. We’re always here to help.
Thank you for choosing Rank Math. Have a great day! 😊
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.