【问题标题】:Set noindex from template - Yoast从模板设置 noindex - Yoast
【发布时间】:2017-04-01 04:42:38
【问题描述】:

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

例如,我有一个名为“Section”的自定义模板,因此,即使使用 API Yoast,也可以使用 Yoast SEO 插件为该模板默认设置 noindex,nofollow?

找到this,但没有关于 noindex、nofollow 函数的信息。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    为了你,我已经这样解决了。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-16
      • 2019-04-12
      • 2014-11-05
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      相关资源
      最近更新 更多