最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin4PV0评论

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;
Post a comment

comment list (0)

  1. No comments so far