I am using this function to get the yoast meta description
$metadesc = get_post_meta( $id, '_yoast_wpseo_metadesc', true );
But it is returning the snippet variable.
From transitional styles %%title%% with soft color palettes to bold
How can I parse that %%variable%%?
I am using this function to get the yoast meta description
$metadesc = get_post_meta( $id, '_yoast_wpseo_metadesc', true );
But it is returning the snippet variable.
From transitional styles %%title%% with soft color palettes to bold
How can I parse that %%variable%%?
Share Improve this question asked Mar 21, 2019 at 14:37 baskinbaskin 313 bronze badges1 Answer
Reset to default 1Ok here is how I parsed the snippets in case anyone else needs to know
$id = get_the_ID();
$post = get_post( $id, ARRAY_A );
$yoast_title = get_post_meta( $id, '_yoast_wpseo_title', true );
$yoast_desc = get_post_meta( $id, '_yoast_wpseo_metadesc', true );
$metatitle_val = wpseo_replace_vars($yoast_title, $post );
$metatitle_val = apply_filters( 'wpseo_title', $metatitle_val );
$metadesc_val = wpseo_replace_vars($yoast_desc, $post );
$metadesc_val = apply_filters( 'wpseo_metadesc', $metadesc_val );
echo $metatitle_val;
echo "<br>";
echo $metadesc_val;