How to set a post noindex from DB
-
Hi Rank Math team,
When saving a post, I would like to automatically set the post to “noindex.”
I tried updating the post meta key
rank_math_robots
with the value “noindex,” and while the meta key value does get updated in the database, it doesn’t reflect on the frontend. The robots tag on the frontend remains as “index.”Additionally, in the Rank Math sidebar of the post edit screen, the post is still marked as “index,” and the checkboxes for “noindex,” “nofollow,” etc., are not selected.
Could you please guide me on how to properly set a post to “noindex” when publishing or updating it?
Here’s the code I’m currently using.
function ayl_noindex_msn_post( $post_id ) {
if( has_term( 'slideshow', 'feed_type', $post_id ) ) {
$arr = ['noindex', 'nofollow', 'noarchive', 'noimageindex', 'nosnippet'];
update_post_meta( $post_id, 'rank_math_robots', serialize( $arr ) );
}
}
add_action( 'save_post', 'ayl_noindex_msn_post' );Could you please let me know what might be missing or how to correctly set a post to “noindex” when publishing or updating it?
Thanks!
The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.