php - Wordpress yoast seo plugin - parse snippet var in meta description

admin2025-04-26  9

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

Ok 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;
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745665710a313017.html

最新回复(0)