Hello,
Thank you for contacting Rank Math support.
You will have to add the following filter to use the global description when an excerpt is present:
add_action( 'rank_math/frontend/description', function( $description ) {
global $post;
$desc = RankMath\Post::get_meta( 'description', $post->ID );
if ( is_single()) {
$desc = RankMath\Helper::get_settings( "titles.pt_{$post->post_type}_description" );
if ( $desc ) {
return RankMath\Helper::replace_vars( $desc, $post );
}
}
return $description;
});
Here is how to add a filter to your site: https://rankmath.com/kb/wordpress-hooks-actions-filters/
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Thank you Jaideep for your response. However, there is an issue.
Currently, with the provided code, the excerpt does not override the global settings, which is expected behavior. However, I would like the meta description entered in the single post editor (as shown in the attached image) to take precedence. In this scenario, the meta description should reflect the editor’s input, but the current behavior still displays the global settings.
Image –
Hello, I’m just following up on an message I previously sent to you. I understand that you are busy, but I would appreciate it if you could review the message and respond to me as soon as you can.
Hello,
We’ve done some slight changes in the code, please refer to the code snippet below instead:
add_action( 'rank_math/frontend/description', function( $description ) {
global $post;
$post_meta_description = RankMath\Post::get_meta( 'description', $post->ID );
if ( $post_meta_description ) {
return $post_meta_description;
}
if ( is_single() ) {
$desc = RankMath\Helper::get_settings( "titles.pt_{$post->post_type}_description" );
if ( $desc ) {
return RankMath\Helper::replace_vars( $desc, $post );
}
}
return $description;
});
Let us know how that goes.
Looking forward to helping you.
Hello,
We are glad to know that this issue has been resolved. Thank you for letting us know.
This ticket will be closed now, but you can always open a new one if you have any other questions or concerns. We are here to help you with anything related to Rank Math.
We appreciate your patience and cooperation throughout this process.
Thank you for choosing Rank Math.