I’m using the WooCommerce
plugin and with it comes the products
post type.
For my site, I’ve created actual pages
for my products, so I don’t need /products
to exist.
Usually, if I had created the post type, I would add publicly_queryable' => false
to make sure the /products
url didn’t exist, but this post type is created by WooCommerce
so unsure how to go about it? Or if it has any implications.
Trying to remove these unnecessary pages from the sitemap.
2
Answers
So this answer came from this post over at the WordPress Stack Exchange site.
Add this to your theme’s functions.php file and give it a try. I tested it on a clean WP install with just WooCommerce installed, and it seems to work as intended.
I added a check to see if the ‘product’ post type exists (please note that your question says the post type is called ‘products’ but it is actually ‘product’). Adding that if/condition helps eliminate errors thrown if WooCommerce wasn’t installed or activated.
If you want to exclude post_type from Yoast SEO sitemap – try this code