Keeping Views with Prevent Direct Access out of XML sitemaps
An XML sitemap lists the URLs on your site that search engines should crawl. Every SEO plugin adds public post types to it, and Views are a public post type, so a View’s own URL ends up in the sitemap even when you only ever show that View embedded in a page. Starting with version 3.4, the Social Sharing & SEO extension removes Views that have Prevent Direct Access enabled from the sitemap, so search engines are not pointed at a URL you have kept off your site.
How it works #
When a View has Prevent Direct Access turned on, the extension tells your sitemap generator to leave that View out. Views that are publicly accessible stay in the sitemap as before. There is nothing to configure: enable the setting on the View and the exclusion follows.
The exclusion covers the sitemap built into WordPress and the sitemaps generated by these plugins:
- Yoast SEO
- Rank Math
- All in One SEO
- SEOPress
- The SEO Framework
- Slim SEO
- Jetpack
- SmartCrawl
Single entry URLs are never listed in a sitemap, because entries are not posts. This setting is about the View’s own URL, such as /view/your-view-name/.
Enabling Prevent Direct Access #
- Edit the View.
- In the Settings box, open the Permissions tab.
- Check Prevent Direct Access.
- Update the View.
You can also change it from the Direct Access line in the Publish box by choosing Embed-only. Both controls set the same option.
Read more: The GravityView Direct Access Setting
Checking your sitemap #
Open the sitemap for the Views post type and confirm the View is no longer listed. Where it lives depends on what generates it:
- WordPress:
/wp-sitemap-posts-gravityview-1.xml - Yoast SEO and Rank Math:
/gravityview-sitemap.xml - Other plugins: start from the sitemap index, usually
/sitemap.xmlor/sitemap_index.xml, and follow the link for Views.
Some plugins cache their sitemap and rebuild it on a schedule or when a post is saved. If a View you just changed still appears, save the View again or clear the sitemap cache from the SEO plugin’s settings, then reload the sitemap.
Views that should stay public but not be indexed #
This exclusion only applies to Views with Prevent Direct Access enabled. For a View that visitors should be able to open at its own URL but that you do not want in search results, use your SEO plugin’s content type settings instead. In Yoast SEO, go to SEO > Search Appearance > Content Types, find Views, and set “Show Views in search results?” to No. Other SEO plugins have an equivalent setting.
Note: Squirrly SEO is not supported. It offers no way to exclude individual posts from its sitemap without affecting every query on the site, so Views appear in its sitemap unless you exclude the post type in Squirrly’s own settings.