Hello,
Thank you for contacting Rank Math today.
If you have added these settings in Rank math > Tiles & Meta > Products, you will need to add the following filter to your theme functions.php file to use setting frmo Global setting if no description is set on the individual product pages:
/**
* 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 ( ! $desc && is_product()) {
$desc = RankMathHelper::get_settings( "titles.pt_{$post->post_type}_description" );
if ( $desc ) {
return RankMathHelper::replace_vars( $desc, $post );
}
}
return $description;
});
This will add the description in the front end. If you wish to override products that have description defined on page please remove ! $desc &&
from the filter.
Looking forward to helping you. Thank you.
Hello,
I have updated the sensitive data as requested. Can you please check further?
Thank you.
Hi Friend,
I am getting an error after updating code in functnion.php of child theme.
Hello,
Apologies about that. I have corrected the code, please use this :
/**
* 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 && is_product()) {
$desc = RankMathHelper::get_settings( "titles.pt_{$post->post_type}_description" );
if ( $desc ) {
return RankMathHelper::replace_vars( $desc, $post );
}
}
return $description;
});
Hope that helps. If you have any further question(s), please let us know. Thank 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.