Hello,
Thank you for your query and we are so sorry about the trouble this must have caused.
Please replace the 3 lines with below instead and see if that works for you:
global $post;
$d1 = RankMath\Paper\Paper::get_from_options( "pt_{$post->post_type}_description", $post, '%excerpt%' );
$d2 = RankMath\Post::get_meta( 'description', $post->ID );
$d3 = RankMath\Post::get_meta( 'rank_math_description', $post->ID );
Let us know how that goes. Looking forward to helping you.
Hello.. this is what I observed.
$d3 is always blank. Not sure how to get it to work.
$d2 requires adding description in the RankMath Snippet.
$d1 is the excerpt of the post that is auto generated by WordPress.
I’m trying to replicate how RankMath generates the description for Social Media tags like og:description where it automaticaly adds description without adding anything to the RankMath snippet.
Can you help?
Hello,
$d3
Can you please confirm if you intend to retrieve the individual post meta description and have the global option of the meta description as your default/fallback?
Please try the code below and see if it works for you:
RankMath\Post::get_meta( 'description', $post->ID, RankMath\Paper\Paper::get_from_options( "pt_{$post->post_type}_description", $post, '%excerpt%' ) );
We have tested this on our local setup with success and this code should work on your website as well.
$d2
This is quite expected. If the description meta is blank, then this will render blank. What you can do here is to add or create a fallback value for this variable.
$d1
Can you please share a screenshot of the current meta description of the post that is shown on the Rank Math SEO metabox?
We really look forward to hearing back from you. Thank you.
If you look at the below screenshot, you can see if the RankMath snippet is blank, there is a default description added my RankMath here. How can I get this default description?
Hello,
That is expected since the meta description for that individual post is technically “blank”, and our plugin’s behavior is to derive from the global settings (Titles & Meta).
In your code, it will only see the blank, not the the global settings so you need to create a logic that will have a fallback.
Hope that helps and please do not hesitate to let us know if you need my assistance with anything else.