• Resolved trmkr

    (@trmkr)


    Hello,

    I want to exclude some products from sitemap. If I disable “Show it in sitemap.xml” option on the product page, product is removed from sitemap. However, if I add noindex meta tag and enable “Automatically exclude from sitemap the URLs with ‘Noindex'” option, product is not removed from sitemap. Can you help please?

    This works:

    This doesn’t work:

    Regards

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Peter

    (@petersquirrly)

    Hi,

    Please try to put in SEO Snippet > Visibility and switch off to “Let Squirrly Index It”.
    Also, can you let us know for which URL and product do you wish to do this?

    Thread Starter trmkr

    (@trmkr)

    Hi Peter,

    I have ~500 products and ~300 of them are out of stock. I want to exclude all out of stock products from sitemap. I would be grateful if there is an easy way to do this. I used this code for noindex tag.

    //Hook the Squirrly sq_noindex for post_ids
    add_filter('sq_noindex', function ($robots) {
        $robots = array();
        global $post;
        if ($post->post_type == 'product') {
    	$product = wc_get_product( $post );
    	if (!$product->is_in_stock())
    		$robots[] = 'noindex';
    		$robots[] = 'nofollow';
        }
        return $robots;
    }, 11);

    Regards

    • This reply was modified 1 year, 7 months ago by trmkr.
    Plugin Support Peter

    (@petersquirrly)

    We just made a dedicated article for this case which can check right here:
    https://howto12.squirrly.co/kb/optimize-your-sitemap-with-squirrly-seo-create-a-custom-hook-to-exclude-out-of-stock-products-and-add-noindex/

    Let us know if you have any other questions.

    Thread Starter trmkr

    (@trmkr)

    Hi Peter,

    Thank you for your efforts! This code solved my problem. I tested it and it works perfectly! Thanks for this great SEO plugin.

    Regards

    Plugin Support Peter

    (@petersquirrly)

    That’s really great to hear! Thank you for the kind words and the confirmation.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘exclude product from sitemap’ is closed to new replies.