Hello,
Thank you for contacting Rank Math today.
I can suggest that you make use of the following filter to check the current post date and add a noindex tag on your theme’s functions.php file:
/**
* Allows filtering of the robots meta data.
*
* @param array $robots The meta robots directives.
*/
add_filter( 'rank_math/frontend/robots', function( $robots ) {
return $robots;
});
Looking forward to helping you. Thank you.
But how can I do so? Technically
Hello,
Thank you for contacting Rank Math today.
You can create some logic to compare the post publish date with a certain cut off date that you have set for old posts as shown below:
/**
* Allows filtering of the robots meta data.
*
* @param array $robots The meta robots directives.
*/
add_filter( 'rank_math/frontend/robots', function( $robots ) {
global $post;
//convert the dates to unix timestamps
$cut_off_date = strtotime( "2019-01-01" );
$post_date = strtotime( $post->post_date );
//compare the current post with the cut off date
if($post_date <= $cut_off_date){
$robots['index'] = 'noindex';
$robots['follow'] = 'follow';
return $robots;
}
return $robots;
});
Looking forward to helping you. Thank you.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.