Currently Available: Need a skilled Software Developer for your next project?
Categories
WordPress

How to Exclude a Page from Yoast SEO XML Sitemap

On a WordPress site, Yoast SEO creates an XML sitemap, a file that lists URLs so search engines can find content.

To remove one page from the sitemap, set it to noindex in Yoast or use a code filter. Noindex also tells search engines to leave the page out of search results, so use the code option if the page should remain eligible to appear there.

Remove the page and noindex it

Edit the page in WordPress and open the Yoast SEO settings. In the Advanced tab, set “Allow search engines to show this content in search results?” to No, then update the page. Yoast excludes noindexed content from its sitemap, as described in a WordPress support discussion.

Choose this option when you want the page omitted from the sitemap and excluded from search results. Search engines need to recrawl the page to process the noindex instruction; removing a URL from the sitemap alone does not issue that instruction.

Exclude the page while keeping it indexable

If the page should remain eligible for search results, use Yoast’s wpseo_exclude_from_sitemap_by_post_ids filter. The filter accepts an array of WordPress post IDs to omit from the sitemap. The code example using the filter shows how to return the IDs to exclude.

Add the following code to a site-specific plugin or other maintained custom code location. Replace 311 with the ID of the page you want to exclude:

add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', function ( $excluded_post_ids ) {
    $excluded_post_ids[] = 311; // Replace with the page's WordPress ID.
    return $excluded_post_ids;
} );

To find the page ID, open the page for editing and look for the number after post= in the browser’s address bar. After adding the filter, check the sitemap output to confirm that the page no longer appears. Because the cited example covers post IDs generally, verify the result for your page and Yoast setup.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

Your email address will not be published. Required fields are marked *