最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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;
发布评论

评论列表(0)

  1. 暂无评论