Support » Plugin: Yoast SEO » Add Custom Post Type Archive To XML Sitemap Without Individual Posts

  • Resolved axlright

    (@axlright)


    How can we add a Custom Post Type archive to the XML sitemap without adding each of the individual Custom Post Type posts to the XML sitemap?

    Usage case would be a listing of reviews where each review is a CPT post and the /reviews/ page is a CPT archive generated by archive-reviews.php

    In this case, each review is not intended to stand on its own as a post or be indexed alone by search engines. However, the aggregate Custom Post Type archive should be indexed and added to the XML Sitemap.

    As of version 7.1 in Search Appearance > Content Types > Custom Post Type Archives, if the CPT Archive is set to Yes for “Show the archive for XXX in search results?”, the archive is not added to the XML sitemap. In order to add the archive to the XML sitemap, the Post Type itself must be set to Yes for “Show XX in search results?” However this also adds every single CPT post in the XML Sitemap.

    How does one go about *not* displaying individual CPT posts in the XML Sitemap while showing the CPT Archive in the XML Sitemap. I guess right now one would have to turn the CPT Archive into a page, but that kind of defeats the purpose of an automated archive-{post_type}.php workflow.

    Thank you!

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

    (@devnihil)

    @axlright If you wish to exclude specific pages/posts you can also exclude them from the sitemap by using the page ID and we have directions for this at the following link: https://kb.yoast.com/kb/sitemap-shows-excluded-posts-pages/

    You can exclude post by IDs using the following to your theme functions.php file:

    add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', function () {
    	return array( 311, 322 );
    } );

    You’ll need to replace the array items with your own posts ID that you’d like to exclude. Once you place the code and save it on your site, please disable and re-enable the XML sitemap from Yoast SEO -> General -> Features (tab) to clear transient cache.

    Thank you @devnihil for the reply.

    I’d like to have only the archive for a custom post type get shown in the XML sitemap, but not any of the custom post type posts.

    For example, we have 1,285 news clips as posts in a Custom Post Type. Each of those news clips should not be individually indexed or listed in the sitemap. The news clips are never meant to be viewed on their own as a single page. Google should not index them individually as a single page. But the archive page showing all 1,285 news clips should be indexed and included in the sitemap.

    This seems to be a common use case, but I can’t seem to achieve the above in the new version 7 settings.

    Per the example above, turning ON the “Show the archive for News Clips in search results?” under Custom Content Type Archives does not add the archive page at …/news-clips/ to the XML index. The only way to get the archive page at …/news-clips/ to the XML index is to turn ON the “Show News Clips in search results?” under the “News Clips (news_clips)” which does then display the archive page at /news-clips/ in the XML Sitemap at …/news_clips-sitemap.xml but also shows all 1,285 individual news clips posts (which aren’t meant to be seen) at urls like …/news-clips/news-item-1/

    So other than adding a filter function to filter out all the individual posts in a custom post type in order to show the custom post type archive in the XML sitemap, is there another way? I feel like this is a pretty common use case.

    Thanks!

    • This reply was modified 1 month, 2 weeks ago by  axlright.
    Plugin Support Md Mazedul Islam Khan

    (@mazedulislamkhan)

    Thanks for clarifying everything. If you go to page-sitemap.xml while the single custom post type item is set to noindex, do you see the custom post type archives page URL on there?

    We have tested this using WooCommerce and we see the /shop/ URL does appear in the page-sitemap.xml while the products are set to noindex.

    Thanks for the reply – we have thousands of custom post type posts. Setting them all to noindex isn’t realistic, nor is adding their post ids to a function to remove them from the sitemap.

    `Custom Content Type Archives
    Note: instead of templates these are the actual titles and meta descriptions for these custom content type archive pages.`

    I don’t understand why choosing YES on items in the above listed section does not add those “custom content type archive pages” to the sitemap. Since they aren’t pages, this is the place to add Page Title, Description or to set whether they are put in the sitemap.xml. That is the expected behavior.

    Many custom post types have posts that individually aren’t meant to be indexed – shopping sites, review sites.

    So how does one add the custom post type archive into the sitemap without the individual posts being added to the sitemap aside from deselecting every single custom post type post?

    Thanks!

    Plugin Support Md Mazedul Islam Khan

    (@mazedulislamkhan)

    If you deselect a custom post type item, you won’t see it in the XML sitemap. If you want to exclude all of the items from a specific custom post types but not that particular custom post types archives page, you will need to select no for the custom post types to noindex but not the archives page. In this way, you archives page will appear in the page-sitemap.xml.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.