Yoast / wordpress-seo

Yoast SEO for WordPress
https://yoast.com/wordpress/plugins/seo/
Other
1.75k stars 886 forks source link

Shop page appears on the product-sitemap even when is set to `noindex` #18754

Open Scabuster opened 2 years ago

Scabuster commented 2 years ago

Please give us a description of what happened.

Yoast XML sitemap is showing page 'Shop' that was blocked in Yoast Advanced tab of Wordpress Pages.

Please describe what you expected to happen and why.

I expect there to be 0 pages in Yoast generated XML sitemap that have been blocked in Yoast Advanced tab of Wordpress Pages. All other pages that have been blocked using the directives in Yoast Advanced tab of Wordpress Pages are successfully not showing up in Yoast generated XML sitemap.

How can we reproduce this behavior?

1) Yoast > General > Features tab > SML sitemaps > Off. 2) WooCommerce > WooCommerce generated page 'Shop'. 3) Wordpress > Pages > Shop > edit > SEO analysis > Advanced tab > Allow search engines to show this Page in search results? No > Should search engines follow links on this Page? No > Meta robots advanced xNo Image Index xNo Archive xNo Snippet. 4) Yoast > General > Features tab > SML sitemaps > On. 5) https://example.com/sitemap_index.xml > https://example.com/product-sitemap.xml > https://example.com/shop/ is still there. This is the only page that does not obey the directives in Yoast Advanced tab of Wordpress Pages as set in 3).

Technical info

Used versions

stodorovic commented 2 years ago

It's expected behaviour. You could install Yoast WooCommerce SEO plugin or use filters to exclude "shop page" from product sitemap (it's added as post_type archive).

add_filter( 'wpseo_sitemap_page_for_post_type_archive', function( $page_id, $post_type ) {
    if ( 'product' === $post_type && function_exists( 'wc_get_page_id' ) ) {
        $page_id = wc_get_page_id( 'shop' );
    }

    return $page_id;
}, 10, 2 );

Related:

7002.

https://wordpress.org/support/topic/cant-exclude-woocommerce-shop-page/

suascat commented 5 months ago

Please inform the customer of conversation #1120890 when this conversation has been closed.

maybellyne commented 1 month ago

+1 https://wordpress.org/support/topic/exclude-shop-page-from-sitemap/

josevarghese commented 1 month ago

The following code will help remove the shop page. Ensure that you test it on a staging site after taking a full backup.

add_filter( 'wpseo_sitemap_url', function ( $output, $url ) {
    $shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );
    if ( $url['loc']  === $shop_page_url) {
        return '';
    }

    return $output;
}, 10, 2 );