-
Hi Rank Math team,
I’m currently using the Rank Math plugin on my WordPress site, and I’d like to customize how the SEO Description field is populated for blog posts.
Specifically, I’d like to:
Use a custom field (post_lead) created via ACF (Advanced Custom Fields) as the SEO Description.
If post_lead is empty or not set, fallback to the post excerpt.
I understand that the %customfield(post_lead)% variable can be used in the Meta Description field via the UI, but it doesn’t seem to support conditional logic or fallbacks.
So my questions are:
Is there any native support or planned support for conditional logic inside the Rank Math variable system (e.g., if custom field is empty, use excerpt)?
Is using the rank_math/frontend/description filter the recommended approach for this kind of logic?
Will applying a filter like this interfere with how Rank Math handles schema or content analysis?
Here’s a simplified version of the code I’m considering:
add_filter( 'rank_math/frontend/description', function( $description ) {
if ( is_singular( 'post' ) ) {
$post_lead = get_field( 'post_lead' );
if ( $post_lead ) {
return wp_strip_all_tags( $post_lead );
} else {
return wp_strip_all_tags( get_the_excerpt() );
}
}
return $description;
});
Just want to confirm if this is the best practice for what I’m trying to do, or if there’s a better Rank Math-native solution that I’ve overlooked.
Appreciate your help and awesome plugin. Looking forward to your guidance.
Best regards,
Vimal
The ticket ‘Using ACF Field (post_lead) as SEO Description with Fallback to Excerpt’ is closed to new replies.