ClodClod91
ClodClod91

Reputation: 314

Set noindex from template - Yoast

With Wordpress plugin's Yoast SEO it's possible set noindex, nofollow from some type of Template that i've create?

For example, i've custom template that i called "Section", so, it's possible set noindex,nofollow by default for this template with Yoast SEO Plugin, even with API Yoast?

Find this but nothing about noindex, nofollow functions.

Upvotes: 1

Views: 2266

Answers (1)

ClodClod91
ClodClod91

Reputation: 314

For you, i've solved in this way.

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

Upvotes: 2

Related Questions