2016-11-17 62 views
1

使用Wordpress插件的Yoast SEO可以设置noindex,从我创建的某种类型的模板设置nofollow?从模板设置noindex - Yoast

例如,我有自定义模板,我称为“部分”,所以,它有可能设置noindex,nofollow这个模板与Yoast SEO插件,即使API Yoast默认?

查找this但没有关于noindex,nofollow的功能。

回答

0

对于你,我已经用这种方式解决了。

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');