I want to eliminate some links and articles from the sitemap page. I have tried using a plugin called "WordPress Simple HTML Sitemap" and even tried from within WordPress itself but haven’t been successful.
Is there a free, effective plugin or another method to do this?
My last resort is to apply CSS {display: none} to those pages using the inspector, but I want a better solution.
I have tried using the third party plugins.
2
Answers
To do it without a plugin, use the
wp_sitemaps_posts_query_args
hook, setting thepost__not_in
argument. Add this code tofunctions.php
:There are plugins like Yoast and Rankmath which allow you to remove specific pages or post from sitemap, but still you want a code then please use this.
Here’s how you can exclude specific pages from the default WordPress sitemap:
Add Code
Open Your Theme’s
functions.php
file.Add the Following Code:
I am using this on my website, so I share it for you.