Hi Danie,
Thanks for getting in touch with us.
This is the order we follow to generate meta descriptions for WooCommerce product:
1. Content from SEO Description field
If that is missing, then:
2. WooCommerce Excerpt or Product Short Description
If that is missing, then:
3. Template From General Settings in WordPress Dashboard > Rank Math > Titles & Meta > Products
If that is missing, then:
4. Auto generated Content from the product page
If you want to show the auto generated description from the content ( step 4 ) then, please add the code which we provided here:
https://wordpress.org/support/topic/make-excerpt-pull-from-product-description-instead-of-short-description/#post-12358847
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Thank you for your reply.
I would prefer Option 3 instead of 2 for product pages only
I found this:
3. Use the Description from Global Setting, if the description is missing in the Post metabox:
/**
* 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 ( ! $desc ) {
$desc = RankMath\Helper::get_settings( “titles.pt_{$post->post_type}_description” );
if ( $desc ) {
return RankMath\Helper::replace_vars( $desc, $post );
}
}
return $description;
});
The problem with this is, that it pulls product description from global settings into products, product categories, posts as well !! Can it be edited so it only pulls into products descriptions please.
Hello Daniel,
Here is the code that will only work for products:
/**
* Use the Description from Global Setting, if the description is missing in the Post metabox
*/
add_action( 'rank_math/frontend/description', function( $generated ) {
global $post;
if ( 'product' !== $post->post_type ) {
return $generated;
}
$desc = RankMath\Helper::get_settings( "titles.pt_{$post->post_type}_description" );
$desc = RankMath\Helper::replace_vars( $desc, $post );
return empty( $desc ) ? $generated : $desc;
});
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
This code does not work. I also need ONLY the post type “product” to pull the meta description from General Settings in WordPress Dashboard > Rank Math > Titles & Meta > Products.
With your code the other post types like product category, ends up with the meta description from the first item on the page.
Can you please correct it?
Hello,
Please replace the code with the following:
add_action( 'rank_math/frontend/description', function( $generated ) {
if ( ! is_product() ) {
return $generated;
}
global $post;
$desc = RankMath\Helper::get_settings( "titles.pt_product_description" );
$desc = RankMath\Helper::replace_vars( $desc, $post );
return empty( $desc ) ? $generated : $desc;
});
This should fix the issue.
-
This reply was modified 4 years, 10 months ago by Pratik.
Looks like it’s working as it should.. Nice one!
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.