Hello @bugnumber9
Thank you for your message.
Can you please tell us which plugin are you using to add the CPTs?
Looking forward to helping you.
Hey @rankmath
Thanks for getting back to me.
I use custom code in functions.php like this: https://gist.github.com/bugnumber9/65d5c7abb6136bd3603db0d053a240f2
Hello @bugnumber9
Sorry for not following up quickly and any inconvenience that might have been caused due to that.y
To noindex lesson archive, please add the following code in functions.php file:
add_filter( 'rank_math/frontend/robots', function( $robots ) {
if ( is_post_type_archive( 'lesson' ) ) {
$robots['index'] = 'noindex';
}
return $robots;
});
Hope that helps. Thank you.
Hi @rankmath,
I added the code to functions.php but it has no effect – https://www.healthtalks365.com/lesson-sitemap.xml
Any idea why? 🙂
Hello @bugnumber9
Sorry for not following up quickly and any inconvenience that might have been caused due to that.
Can you please follow these steps?
1. Flush the Sitemap cache by following this video screencast:
https://i.rankmath.com/xXXhDt
2. Exclude the Sitemap files of the Rank Math plugin in your caching plugin. The cache could be via a plugin or from the server. For plugins or Cloudflare, please follow this article:
https://rankmath.com/kb/exclude-sitemaps-from-caching/
That should fix the issue. Please let us know if that does not. We are here to assist.
Hey @rankmath,
I did everything you suggested, still no effect.
What can I do to help you troubleshoot this?
Hello @bugnumber9
Sorry for not following up quickly and any inconvenience that might have been caused due to that.
The code we gave you will add NoIndex to the Lesson archive page on the frontend.
To remove the archive link from the Sitemap, you will have to use the following filter:
https://rankmath.com/kb/filters-hooks-api-developer/#change-remove-archive-url
Example code:
add_filter( 'rank_math/sitemap/post_type_archive_link', function( $archive_url, $post_type ){
if ( 'lesson' === $post_type ) {
return false;
}
return $archive_url;
}, 10, 2 );
Hope that helps.
Hi @rankmath,
Sorry for the late reply. Everything works fine now, thanks a lot!
Hello,
Glad that helped.
Please feel free to reach out to us again in case you need any other assistance.
We are here to help. Thank you.