I found this code from you and it works, but it applies meta product description and for product categories and product attributes.
How can I make this code work specifically for products?
Regards Denis
/**
* 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;
});
Hello,
Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.
In the filter, you’ll need to update the line ! $desc
to is_product()
Here’s the full code you can copy as well:
/**
* 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;
});
Also, please note that the filter may not be visible while editing the products as it only works when your products load in a browser. You can check the published product meta description via the page’s source code. You can also check using this tool.
I hope that helps.
Thank you.
Thank you so much!
It worked!
Regards Denis.
Hello,
I am happy it helped you. Do you have any other questions or do you want us to mark this as solved?
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.