2016-11-17 4 views
1

WordpressプラグインのYoast SEOでは、作成したテンプレートの一部のタイプからnoindex、nofollowを設定することは可能ですか?テンプレートからnoindexを設定する - Yoast

たとえば、「セクション」と呼ばれるカスタムテンプレートがあります。したがって、Yoast SEO Pluginを使用してこのテンプレートにデフォルトでnoindex、nofollowを設定することは可能です。

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'); 
関連する問題