-
Hello,
We have a problem with Rank Math SEO Noindex robots tag.We are applying noindex to our some of old posts from year 2017 to 2022 using hook rank_math/frontend/robots, it works fine, and adding noindex in frontend , but sitemap still showing up those noindex posts.
If we apply noindex from backend post edit screen then it works fine, sitemap also not displaying that post. But we cannot apply changes from backend as there are many posts.
Why sitemap showing up noindex posts if we use hook rank_math/frontend/robots.
Please provide solution ASAP
Here is our code
add_filter( 'rank_math/frontend/robots', function( $robots ) { global $post; // Check if the post belongs to the "haberler" category if ( has_category( 'haberler', $post->ID ) ) { // Get the publication date of the post $post_date = get_the_date( 'Y-m-d', $post->ID ); // Convert the publication date to a DateTime object $publication_date = new DateTime( $post_date ); // Define the start and end dates for the range (2017-01-01 to 2022-12-31) $start_date = new DateTime( '2017-01-01' ); $end_date = new DateTime( '2022-12-31' ); // Check if the publication date is within the specified range if ( $publication_date >= $start_date && $publication_date <= $end_date ) { unset( $robots['index'] ); $robots['noindex'] = 'noindex'; } } return $robots; });
The ticket ‘Noindex posts displayed in Sitemap.’ is closed to new replies.