Type something to search...
How to create an XML sitemap in WordPress?

How to create an XML sitemap in WordPress?

WordPress already creates an XML sitemap for you. Since WordPress 5.5, every site automatically generates one at https://yourdomain.com/wp-sitemap.xml, listing your posts, pages, categories, tags, and author archives. If you want more control, such as excluding specific content or adding image data, an SEO plugin like Yoast SEO, Rank Math, or All in One SEO replaces the core sitemap with its own. Either way, the final step is to submit the sitemap URL to Google Search Console and Bing Webmaster Tools.

A sitemap is a small technical detail, but it helps search engines find and understand your content, especially on new sites or sites with lots of pages. This guide explains what an XML sitemap is, how to check and customize WordPress's built-in version, how to use an SEO plugin instead, and how to submit and troubleshoot your sitemap.

What Is an XML Sitemap?

An XML sitemap is a file that lists the URLs on your website that you want search engines to know about. It can also include extra details, such as when each page was last modified. Search engines like Google and Bing read the file to discover pages they might otherwise miss or take longer to find.

Here's what a simple sitemap entry looks like:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://yourdomain.com/how-to-bake-bread/</loc>
    <lastmod>2026-09-20T08:30:00+00:00</lastmod>
  </url>
</urlset>

Large sites usually use a sitemap index, which is a sitemap of sitemaps. It points to separate files for posts, pages, categories, and so on. WordPress and most SEO plugins work this way.

XML Sitemaps vs. HTML Sitemaps

An XML sitemap is written for search engines. An HTML sitemap is a regular page listing your content for human visitors. They serve different purposes, and you don't need an HTML sitemap for SEO, though it can help visitors on large sites.

Why Does Your WordPress Site Need a Sitemap?

Search engines mostly discover pages by following links. A sitemap supplements that by giving them a direct list. It's especially helpful when:

  • Your site is new: There are few external links pointing to it yet.
  • Your site is large: Hundreds or thousands of pages can take a while to crawl fully.
  • Some pages are poorly linked: Content that isn't linked from menus or other posts can be missed.
  • You publish often: Updated lastmod dates help search engines notice fresh content.

A sitemap doesn't guarantee that pages will be indexed or rank well. It's a discovery aid, not a ranking factor. Quality content and good internal linking still matter most.

Method 1: Use the Built-In WordPress Sitemap

If you don't use an SEO plugin, you already have a working sitemap.

Check Your Sitemap

Visit https://yourdomain.com/wp-sitemap.xml in your browser. You should see a sitemap index linking to individual sitemaps, such as:

  • wp-sitemap-posts-post-1.xml for blog posts
  • wp-sitemap-posts-page-1.xml for pages
  • wp-sitemap-taxonomies-category-1.xml for categories
  • wp-sitemap-taxonomies-post_tag-1.xml for tags
  • wp-sitemap-users-1.xml for author archives

Public custom post types and taxonomies are included automatically. Each sitemap file holds up to 2,000 URLs by default, and additional files are created as needed.

If the Sitemap Doesn't Appear

  • Check search engine visibility: Go to Settings > Reading. If "Discourage search engines from indexing this site" is checked, WordPress disables the sitemap. Uncheck it when you're ready for search engines to crawl the site.
  • Check for an SEO plugin: Many SEO plugins turn off the core sitemap and replace it with their own at a different URL.
  • Re-save permalinks: Visit Settings > Permalinks and click "Save Changes" to flush rewrite rules.
  • Check plain permalinks: If your site uses plain permalinks, the sitemap is at /?sitemap=index instead.

Customize the Core Sitemap With Code

The core sitemap is intentionally simple, but WordPress provides filters to customize it. Add these snippets to a small custom plugin or your child theme's functions.php.

Remove author archives from the sitemap. Author archives often add little value on single-author blogs:

function sajjad_remove_users_sitemap( $provider, $name ) {
    if ( 'users' === $name ) {
        return false;
    }
    return $provider;
}
add_filter( 'wp_sitemaps_add_provider', 'sajjad_remove_users_sitemap', 10, 2 );

Remove tags from the sitemap:

function sajjad_remove_tags_from_sitemap( $taxonomies ) {
    unset( $taxonomies['post_tag'] );
    return $taxonomies;
}
add_filter( 'wp_sitemaps_taxonomies', 'sajjad_remove_tags_from_sitemap' );

Exclude a custom post type:

function sajjad_remove_cpt_from_sitemap( $post_types ) {
    unset( $post_types['portfolio'] );
    return $post_types;
}
add_filter( 'wp_sitemaps_post_types', 'sajjad_remove_cpt_from_sitemap' );

Exclude specific posts or pages by ID, such as a thank-you page:

function sajjad_exclude_posts_from_sitemap( $args, $post_type ) {
    if ( 'page' !== $post_type ) {
        return $args;
    }

    $args['post__not_in'] = isset( $args['post__not_in'] ) ? $args['post__not_in'] : array();
    $args['post__not_in'] = array_merge( $args['post__not_in'], array( 42, 57 ) );

    return $args;
}
add_filter( 'wp_sitemaps_posts_query_args', 'sajjad_exclude_posts_from_sitemap', 10, 2 );

Change the number of URLs per sitemap file:

function sajjad_sitemap_max_urls( $max_urls, $object_type ) {
    return 1000;
}
add_filter( 'wp_sitemaps_max_urls', 'sajjad_sitemap_max_urls', 10, 2 );

Disable the core sitemap entirely, for example if you generate one another way:

add_filter( 'wp_sitemaps_enabled', '__return_false' );

After adding filters, visit your sitemap to confirm the changes. If you use a caching plugin, clear the cache first.

Method 2: Use an SEO Plugin's Sitemap

Most WordPress SEO plugins generate their own sitemap, which offers more options without code. If you already use one, you probably don't need to do anything except confirm the sitemap is enabled.

Yoast SEO

  1. Install and activate Yoast SEO: From Plugins > Add New Plugin.
  2. Confirm sitemaps are on: Go to Yoast SEO > Settings > Site features and make sure "XML sitemaps" is enabled.
  3. View the sitemap: Click "View the XML sitemap," or visit https://yourdomain.com/sitemap_index.xml.
  4. Exclude content types: Under Yoast SEO > Settings > Content types, turn off "Show in search results" for any type you don't want indexed. Yoast also removes it from the sitemap.
  5. Exclude individual posts: In the Yoast panel for a post, under Advanced, set "Allow search engines to show this content in search results?" to "No."

Rank Math

  1. Install and activate Rank Math: Run the setup wizard.
  2. Enable the Sitemap module: Go to Rank Math > Dashboard and make sure the "Sitemap" module is active.
  3. Configure settings: Open Rank Math > Sitemap Settings to choose which post types and taxonomies to include, whether to include images, and how many links per sitemap.
  4. View the sitemap: Rank Math's sitemap index is at https://yourdomain.com/sitemap_index.xml.

All in One SEO

  1. Install and activate AIOSEO.
  2. Open the sitemap settings: Go to All in One SEO > Sitemaps.
  3. Enable and configure: Make sure the general sitemap is enabled, then choose post types, taxonomies, and any additional pages.
  4. View the sitemap: AIOSEO's sitemap is typically at https://yourdomain.com/sitemap.xml.

Which Approach Should You Use?

  • Core sitemap: Fine for small, simple sites that don't use an SEO plugin, especially if you're comfortable with a few filters.
  • SEO plugin sitemap: Better if you already use an SEO plugin, want image entries, need point-and-click exclusions, or want the sitemap to follow per-post "noindex" settings automatically.

Avoid running two sitemaps at once. If you install an SEO plugin, let it handle the sitemap, and submit only its URL to search engines.

Step 3: Submit Your Sitemap to Search Engines

Search engines can discover your sitemap on their own, but submitting it directly helps them find it faster and gives you reporting on any issues.

Google Search Console

  1. Verify your site: If you haven't already, add your site as a property in Google Search Console. A Domain property verified by a DNS TXT record covers every version of your domain.
  2. Open the Sitemaps report: Go to Indexing > Sitemaps in the left menu.
  3. Add your sitemap URL: Enter wp-sitemap.xml, or sitemap_index.xml if you use Yoast or Rank Math, and click "Submit."
  4. Check the status: After processing, the report should show "Success" along with the number of discovered URLs.

Bing Webmaster Tools

  1. Add your site: Sign in to Bing Webmaster Tools. You can import your site directly from Google Search Console to save time.
  2. Open Sitemaps: Select "Sitemaps" from the menu.
  3. Submit: Enter the full sitemap URL and click "Submit."

Bing's index also powers several other search services, so this step covers more than just Bing itself.

Step 4: Reference Your Sitemap in robots.txt

Search engines check robots.txt for a Sitemap: line. WordPress's virtual robots.txt automatically includes the core sitemap when it's enabled, and SEO plugins typically add their own. You can check by visiting https://yourdomain.com/robots.txt.

If you have a physical robots.txt file in your site's root folder, WordPress's virtual one is ignored, so make sure your file includes the line yourself:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php

Sitemap: https://yourdomain.com/sitemap_index.xml

If you prefer to keep the virtual file and just add a line, use the robots_txt filter:

function sajjad_add_sitemap_to_robots( $output, $public ) {
    if ( $public ) {
        $output .= "\nSitemap: " . esc_url( home_url( '/sitemap_index.xml' ) ) . "\n";
    }
    return $output;
}
add_filter( 'robots_txt', 'sajjad_add_sitemap_to_robots', 10, 2 );

Only do this if the line isn't already there, since duplicate entries aren't harmful but are untidy.

Troubleshooting Common Sitemap Problems

Sitemap returns a 404: Re-save permalinks, check that search engine visibility is enabled under Settings > Reading, and confirm which URL your SEO plugin uses.

"Couldn't fetch" in Search Console: This is often temporary. Check that the sitemap loads in a private browser window, that it isn't blocked by robots.txt, a firewall, or a security plugin, and resubmit after a while.

Sitemap shows old content or missing posts: Clear your caching plugin and CDN cache. Some caching setups store sitemap pages, which can make them stale.

Blank page or XML errors: Whitespace or PHP output before the XML declaration, often caused by a stray space at the end of functions.php or a plugin, breaks the XML. Deactivate recently added plugins and check for trailing whitespace after a closing ?> tag.

Noindexed pages appearing in the sitemap: SEO plugins remove noindexed content automatically. With the core sitemap, you need to exclude them with filters, as shown above.

Redirected URLs listed: Make sure your site address under Settings > General matches your preferred URL, including https:// and www or non-www.

Sitemap Best Practices

  • Include only indexable, canonical URLs: Don't list redirects, noindexed pages, or duplicate URLs.
  • Keep thin archives out: Consider excluding tag archives, author archives, or attachment pages if they add little value.
  • Use one sitemap source: Let either WordPress core or your SEO plugin handle it, not both.
  • Check Search Console regularly: The Pages report shows which submitted URLs were indexed and why others weren't.
  • Don't obsess over priority and changefreq: Google has said it ignores these values, and the core sitemap doesn't include them.

FAQ: XML Sitemaps in WordPress

Yes. Since WordPress 5.5, core generates a sitemap at /wp-sitemap.xml, as long as search engine visibility is enabled under Settings > Reading and no plugin has replaced it.

For the core sitemap, it's /wp-sitemap.xml. Yoast SEO and Rank Math use /sitemap_index.xml, and All in One SEO typically uses /sitemap.xml.

Not necessarily. The core sitemap works well for many sites. An SEO plugin is helpful if you want point-and-click exclusions, image entries, or tighter integration with noindex settings.

You only need to submit it once. Search engines re-crawl it regularly and pick up new URLs automatically. Resubmit only if you change the sitemap URL.

A sitemap helps discovery but doesn't guarantee indexing. Google may skip pages it considers low quality, duplicate, or unimportant. The Pages report in Search Console explains the reasons.

Yes. A sitemap index can reference many sitemap files, and you can submit several sitemaps in Search Console. Just avoid having two competing systems, like core and an SEO plugin, both generating sitemaps.


Conclusion

Creating an XML sitemap in WordPress is mostly a matter of confirming the one you already have. WordPress core generates a sitemap automatically, and you can refine it with a few filters. If you use an SEO plugin like Yoast SEO, Rank Math, or All in One SEO, its sitemap takes over and gives you more options without code.

Whichever route you choose, submit your sitemap to Google Search Console and Bing Webmaster Tools, make sure it's referenced in robots.txt, and check the reports occasionally for errors. A clean, accurate sitemap won't replace great content and solid internal links, but it makes sure search engines never miss the pages you want them to find.

Tags :
Share :

Related Posts

What are the best WordPress security plugins?

What are the best WordPress security plugins?

The best WordPress security plugins for most sites are Wordfence, Sucuri Security, Solid Security, MalCare, All-In-One Security (AIOS), Patchstack, a

Dive Deeper
What is the difference between posts and pages in WordPress?

What is the difference between posts and pages in WordPress?

The main difference between posts and pages in WordPress is that posts are timely, dated entries that appear in your blog feed, archives, and RSS fee

Dive Deeper
How much does it cost to build a WordPress website?

How much does it cost to build a WordPress website?

Building a WordPress website can cost anywhere from roughly the price of a domain and a year of budget hosting, if you do it yourself with free tools

Dive Deeper