【发布时间】:2017-04-01 04:42:38
【问题描述】:
使用 Wordpress 插件的 Yoast SEO,可以从我创建的某种模板中设置 noindex、nofollow?
例如,我有一个名为“Section”的自定义模板,因此,即使使用 API Yoast,也可以使用 Yoast SEO 插件为该模板默认设置 noindex,nofollow?
找到this,但没有关于 noindex、nofollow 函数的信息。
【问题讨论】:
使用 Wordpress 插件的 Yoast SEO,可以从我创建的某种模板中设置 noindex、nofollow?
例如,我有一个名为“Section”的自定义模板,因此,即使使用 API Yoast,也可以使用 Yoast SEO 插件为该模板默认设置 noindex,nofollow?
找到this,但没有关于 noindex、nofollow 函数的信息。
【问题讨论】:
为了你,我已经这样解决了。
function set_noindex_nofollow($post_id){
if ( wp_is_post_revision( $post_id ) ) return;
if ( strpos(get_page_template_slug($post_id),'section') !== false){
add_action( 'wpseo_saved_postdata', function() use ( $post_id ) {
update_post_meta( $post_id, '_yoast_wpseo_meta-robots-noindex', '1' );
update_post_meta( $post_id, '_yoast_wpseo_meta-robots-nofollow', '1' );
}, 999 );
}else{
return;
}
}
add_action( 'save_post', 'set_noindex_nofollow' );
【讨论】: