I am a content supervisor on a wordpress site, it uses wordpress seo by yoast plugin. My duty includes analyzing the content and marking it sticky if seems fit. When I mark a particular post as sticky, there is a function which then sets the post to only appear on the category page. Next thing I have to do is manually set the single-post-view to no-index as instructed by the site-owner.

Since the site is huge, this process is really getting tedious so I am looking for a way to partly automate this process. I am trying to put together a function, which sets the post to no-index, as soon as I update the post as sticky.

First, I would like to know which wp-function is fired when a post is set to sticky. Second, since the site uses yoast's seo-plugin, I would like to know about the seo-plugin's hook/filter which sets the post to no-index. Looking for relevant filters or hooks I found the seo-plugin API page of yoast which has a few filters but I could not find anything that could be useful for my purpose.


2 Answers 2


In my effort to solve this I discovered a great resource for wordpress hooks for the job and found the right hook wpseo_saved_postdata here. Feel free to modify the code if you think it could be better. For now, it works for me.

function set_noidex_when_sticky($post_id){
        if ( wp_is_post_revision( $post_id ) ) return;
        //perform other checks

        //if(is_sticky($post_id)){ -----> this may work only AFTER the post is set to sticky
        if (isset($_POST['sticky']) == 'sticky') { //this will work if the post IS BEING SET ticky  
            add_action( 'wpseo_saved_postdata', function() use ( $post_id ) { 
            update_post_meta( $post_id, '_yoast_wpseo_meta-robots-noindex', '1' );
            }, 999 );
 add_action( 'save_post', 'set_noidex_when_sticky' );

Only _yoast_wpseo_meta-robots-noindex was the meta I was targeting to change. Given below are some of yoast's meta keys, if you wanna make any change using the code.


Why don't you just check if the post is sticky and then add noindex? You can use the Conditional Tag is_sticky().

So, in your <head> tag in your header.php file, do the following check:

if ( is_sticky() && is_single() ) {
    // it's a post and it's sticky, let's add noindex
    echo '<meta name="robots" content="noindex">';
  • 1
    I thought about this way, but wont there be two meta-robots declarations, one through this function and another added by the seo-plugin ?
    – gurung
    Jun 28, 2015 at 18:01
  • Yes it would, then again, we have: moz.com/community/q/… Maybe if you can find the function that outputs that declarations, we could hook into it. I think Yoast has hooks...
    – Christine Cooper
    Jun 28, 2015 at 18:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.