Hello,
I apologize for the inconvenience you are facing with the Single Product Description in the WooCommerce Product post type.
Based on your description, it seems like there might be a configuration issue with how the Single Product Description is set up in Rank Math. To ensure that the Single Product Description is displayed correctly without manual input on each product, you need to follow the correct steps to configure it.
To set the Single Product Description globally for all products, you can use a filter provided by Rank Math. By adding this filter, you can override the order of priority and make the Single Product Description the meta description for all your products.
Here is the filter code snippet you can use:
/**
* Use the Description from Global Setting, if the description is missing in the Post metabox
*/
add_action( 'rank_math/frontend/description', function( $description ) {
global $post;
$desc = RankMathPost::get_meta( 'description', $post->ID );
if ( is_product()) {
$desc = RankMathHelper::get_settings( "titles.pt_{$post->post_type}_description" );
if ( $desc ) {
return RankMathHelper::replace_vars( $desc, $post );
}
}
return $description;
});
By adding this filter, the Single Product Description will be used as your meta description for all products.
If you need further assistance or clarification on implementing this filter, please let us know. Thank you for reaching out, and we are here to help you resolve this issue.
Kind regards.
Sources:
How to Set Product Meta Description Using Rank Math » Rank Math
Rank Math ‘Titles and Meta’ Options and Settings
I get Uncaught Error: Class “RankMathPost” not found with that code snippet
Hello,
Thank you for contacting us and sorry for any inconvenience that this issue might have caused.
You can use the below filter instead to override the order of priority and make the single product description the meta description of all your products.
/**
* Use the Description from Global Setting, if the description is missing in the Post metabox
*/
add_action( 'rank_math/frontend/description', function( $description ) {
global $post;
$desc = RankMath\Post::get_meta( 'description', $post->ID );
if ( is_product()) {
$desc = RankMath\Helper::get_settings( "titles.pt_{$post->post_type}_description" );
if ( $desc ) {
return RankMath\Helper::replace_vars( $desc, $post );
}
}
return $description;
});
You can refer to this guide on how to add filters to your site: https://rankmath.com/kb/filters-hooks-api-developer/
Once you’ve added the filter, the single product description will be used as your meta description.
Let us know how it goes. Looking forward to helping you.
Thank you.
I also used AI to get that same snippet and it does not work, the original snippet works, but the front end just errors to an “Uncaught Error: Class “RankMathPost”
Hello,
There were some errors in the code snippets shared by RankBot. The correct class is RankMath\Post
and RankMath\Helper
, not RankMathPost and RankMathHelper respectively.
Please try the code we shared in the last reply and let us know if it works for you.
We look forward to helping you.
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.