Hello,
Thank you for contacting Rank Math for help with setting a general product category meta description.
You can set a generic product category meta description by going to your WordPress dashboard > Rank Math > Titles & Meta > Product categories and set the general meta title and description there.
Hope that helps. Please let us know if you have questions.
Hi,
thank you but this does not solve my question. Please read my question again!
I have product categories where I have a category description(NOT eta description! Category description is the text that is visibe to the customer o front end and is a description of the product category. It is set on Woocommerce categroy pages at the very top). For these pages where I have written a category description, Rank Math should use this category description as he meta description.
But then I have other product categories where I have NOT written a category description text. In these cases, Rank Math should pull from a generic text with variables. How can I achieve this? Rank Math only has options to set ONE generic text, but as you see I have two cases: one where it should pull from %term_description and when there is no %term_description it should be something else with other variables.
Hello,
Thank for the clarification. To set a category meta description that is implemented only when the category page main description field is empty, you will need to customize the following filter:
add_filter( 'rank_math/frontend/description', function( $description ) {
if ( is_category() ) {
$term = get_queried_object();
if ( empty( $term->description ) ) {
$description = 'Your custom category description here';
}
}
return $description;
});
You will need to replace 'Your custom category description here'
with the relevant category meta description variables.
You can follow this guide for how to add a filter to your website: https://rankmath.com/kb/wordpress-hooks-actions-filters/
Hope that helps. Please let us know if you have questions.
Hi,
thanks. I needed to change category to product_category since I need it for product categories. But I still cannot enter any variables in the filter you provided – it will get display as %title% in the meta description for example.
Hello,
Please refer to the modified filter code below target product categories and pre-process the variable you have added to the description:
add_filter( 'rank_math/frontend/description', function( $description ) {
if ( is_product_category() ) {
$term = get_queried_object();
if ( empty( $term->description ) ) {
$description = RankMath\Helper::replace_vars('Your custom category description here');
}
}
return $description;
});
Hope that helps and please do not hesitate to let us know if you need my assistance with anything else.
This just removes the variable. For example, if I use
$description = RankMath\Helper::replace_vars('%title% - buy now!');
The result is
<meta name="description" content="- buy now!"/>
Hello,
Sorry for not catching that earlier, please use %term% instead of %title% for taxonomy pages
Hope that helps. Please let us know if you have questions.
Hello,
We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.
If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.
If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
Thank you.