显示默认的Yoast SEO类别说明

时间:2017-05-01 09:41:28

标签: php wordpress plugins

我需要在我的档案模板中显示Yoast SEO(wpseo插件)类别描述模板。

我需要在我的存档模板上显示:

My site %%term_title%%. In category %%term_title%%.

这有可能实现吗?如果是这样,怎么样?

1 个答案:

答案 0 :(得分:0)

OK!我找到了一个能够完美解决问题的答案here

这是代码:

获取类别,分类档案,页面,帖子的WPSEO标题和说明

// access wpseo_frontend class and get the seo title and seo description for output on archive pages
if ( class_exists( 'WPSEO_Frontend' ) ) {
    $wpseo_object = WPSEO_Frontend::get_instance();
    $headline = $wpseo_object->title( false );
    $intro_text = $wpseo_object->metadesc( false );
}
$headline = sanitize_text_field( $headline );
$intro_text = sanitize_text_field( $intro_text );
// these should work if not archives
# $headline = get_post_meta( $post->ID, '_yoast_wpseo_title', true );
# $intro_text = get_post_meta( $post->ID, '_yoast_wpseo_metadesc', true );

非常感谢Chuck Reynolds

相关问题