
How to Add an XML Sitemap to WordPress?
An XML sitemap is a map of your site handed directly to search engines, listing every URL you want indexed along with metadata like when it was last modified. Search engines can discover pages by crawling links, but a sitemap makes that process faster and more reliable, especially for large sites, sites with pages that aren't well-linked internally, or sites that publish new content frequently.
The good news is that WordPress has generated a basic XML sitemap automatically since version 5.5, with no plugin required. This guide covers what that built-in sitemap does, how to extend or replace it, and how to submit it to Google and Bing.
WordPress's Built-In Sitemap
If you're running WordPress 5.5 or later with default settings, visit:
https://example.com/wp-sitemap.xml
You'll see an index file listing sub-sitemaps for posts, pages, categories, tags, and authors, something like:
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://example.com/wp-sitemap-posts-post-1.xml</loc>
<lastmod>2026-09-01T10:15:00+00:00</lastmod>
</sitemap>
<sitemap>
<loc>https://example.com/wp-sitemap-posts-page-1.xml</loc>
<lastmod>2026-08-20T14:02:00+00:00</lastmod>
</sitemap>
<sitemap>
<loc>https://example.com/wp-sitemap-taxonomies-category-1.xml</loc>
<lastmod>2026-08-15T09:30:00+00:00</lastmod>
</sitemap>
</sitemapindex>
Each linked sub-sitemap then lists individual URLs. This works out of the box with zero configuration, but it's fairly bare-bones: no priority values, no image sitemap entries, and limited control over what's included.
Disabling the Built-In Sitemap (If You Need To)
If you're switching to an SEO plugin's sitemap (covered below) and want to avoid running two sitemaps at once, disable the core one with a filter in your theme's functions.php or a site-specific plugin:
add_filter( 'wp_sitemaps_enabled', '__return_false' );
Most SEO plugins do this automatically when their own sitemap module is active, but it's worth confirming only one sitemap is actually live.
Method 1: Use Yoast SEO
Yoast is the most widely used SEO plugin and includes sitemap generation as a core feature.
- Install and activate Yoast SEO from Plugins > Add New.
- Go to Yoast SEO > Settings, then under the General tab find Site features or XML sitemaps (label varies by version) and confirm it's enabled.
- Your sitemap is now live at:
https://example.com/sitemap_index.xml
Yoast automatically excludes noindexed content, splits large sitemaps across multiple files, and lets you control which post types and taxonomies are included from Yoast SEO > Settings > Content Types.
Method 2: Use Rank Math
Rank Math is a popular alternative with a similarly capable sitemap module.
- Install and activate Rank Math.
- Go to Rank Math > Sitemap Settings.
- Toggle which post types, taxonomies, and archives to include.
- Your sitemap is live at:
https://example.com/sitemap_index.xml
Rank Math also supports image sitemap entries and lets you exclude specific individual posts or pages by ID.
Method 3: Build a Custom Sitemap Entry Manually
If you have a custom post type or a set of URLs that don't come from WordPress content at all (a generated report, an external resource list), you can hook into the core sitemap API to add them without a plugin:
add_filter( 'wp_sitemaps_post_types', function ( $post_types ) {
// Ensure a custom post type called "product" is included.
if ( isset( $post_types['product'] ) ) {
$post_types['product']->set( 'public', true );
}
return $post_types;
} );
Or, to add entirely custom, non-post URLs as their own sitemap provider:
add_action( 'init', function () {
if ( ! function_exists( 'wp_register_sitemap_provider' ) ) {
return;
}
class Custom_Sitemap_Provider extends WP_Sitemaps_Provider {
public function __construct() {
$this->name = 'custom-pages';
$this->object_type = 'custom-page';
}
public function get_url_list( $page_num, $object_subtype = '' ) {
return [
[
'loc' => home_url( '/special-landing-page/' ),
],
];
}
public function get_max_num_pages( $object_subtype = '' ) {
return 1;
}
}
wp_register_sitemap_provider( 'custom-pages', new Custom_Sitemap_Provider() );
} );
This is a more advanced approach, and for most sites an SEO plugin's settings screen will cover what you need without writing custom PHP.
Image Sitemaps
If a meaningful part of your traffic comes from image search — a photography portfolio, a recipe site, a product catalog — including image data in your sitemap can help those images surface in Google Image Search. WordPress's core sitemap doesn't include image data by default, but you can add it with a filter:
add_filter( 'wp_sitemaps_posts_entry', function ( $sitemap_entry, $post ) {
$image_id = get_post_thumbnail_id( $post );
if ( $image_id ) {
$image_url = wp_get_attachment_image_url( $image_id, 'full' );
if ( $image_url ) {
$sitemap_entry['images'] = [ $image_url ];
}
}
return $sitemap_entry;
}, 10, 2 );
Both Yoast and Rank Math include automatic image sitemap support as part of their standard sitemap module, pulling in featured images and images embedded in post content without any extra configuration, which is usually the simpler route unless you need custom logic like the filter above.
Sitemaps for Custom Post Types
If your site uses custom post types (a portfolio, a documentation section, a job listings type), confirm they're actually included in the sitemap. WordPress's core sitemap only includes a public post type automatically if it was registered with 'public' => true and doesn't explicitly opt out:
register_post_type( 'portfolio', [
'public' => true,
'show_in_rest' => true,
'has_archive' => true,
// ...other args
] );
If a custom post type was registered with 'public' => false (sometimes done for post types meant to power internal functionality rather than be publicly browsable) but you still want its individual entries indexed, you can explicitly add it back into the sitemap:
add_filter( 'wp_sitemaps_post_types', function ( $post_types ) {
if ( post_type_exists( 'portfolio' ) ) {
$post_types['portfolio'] = get_post_type_object( 'portfolio' );
}
return $post_types;
} );
Both Yoast and Rank Math surface a toggle for each registered post type under their sitemap settings, so check there first before reaching for a custom filter.
Sitemaps on WordPress Multisite
Each site in a WordPress multisite network gets its own independent sitemap at its own subdomain or subdirectory (site1.example.com/wp-sitemap.xml, example.com/site2/wp-sitemap.xml), generated the same way as a single-site install. There's no single network-wide sitemap covering every site by default — if you need one (for a network-wide search feature, for instance), that requires custom development to aggregate URLs across sites, since core WordPress and most SEO plugins treat each site's sitemap independently.
Troubleshooting Common Sitemap Issues
Sitemap returns a 404 itself. Confirm permalinks aren't set to "Plain" under Settings > Permalinks — the core sitemap depends on WordPress's rewrite rules, and a plain permalink structure can prevent /wp-sitemap.xml from resolving. Re-saving the permalinks settings (even without changing anything) flushes rewrite rules and often fixes this.
Sitemap shows old or missing URLs after a migration. If you've recently moved domains, cached versions of robots.txt or the sitemap itself (either server-side caching or a CDN) can serve stale content. Purge any relevant caches and re-submit the sitemap in Search Console.
Google Search Console reports "Couldn't fetch." This usually means Googlebot couldn't reach the sitemap URL at the time it tried, often due to a firewall, security plugin, or robots.txt rule blocking crawler access. Confirm the sitemap loads for a logged-out visitor and isn't blocked by a Disallow rule in robots.txt.
Sitemap includes URLs that 404 or redirect. This typically means content was deleted or moved without updating references, or a plugin conflict is generating stale entries. SEO plugins regenerate their sitemap dynamically on request, so this is more often a sign of leftover cached output than a real ongoing issue — clear any page cache covering the sitemap URL itself.
Submitting Your Sitemap to Google and Bing
Generating the sitemap is only half the job — search engines need to know it exists.
Google Search Console
- Sign in to Google Search Console and verify ownership of your site if you haven't already.
- Go to Sitemaps in the left sidebar.
- Enter your sitemap path (e.g.
sitemap_index.xmlorwp-sitemap.xml) and click Submit. - Google will periodically crawl the sitemap going forward; check back on this screen to see how many URLs were discovered versus indexed.
Bing Webmaster Tools
- Sign in to Bing Webmaster Tools and verify your site.
- Go to Sitemaps and submit the same sitemap URL.
Reference It in robots.txt
It's good practice to also point to your sitemap from robots.txt, so any crawler respecting that convention can find it without a manual submission:
Sitemap: https://example.com/sitemap_index.xml
WordPress generates robots.txt virtually by default; most SEO plugins add this line automatically once their sitemap module is active, or let you edit robots.txt directly from their settings screen.
Keeping Your Sitemap Healthy
- Check Search Console's Sitemaps report periodically for errors like URLs that return 404s or are blocked by
robots.txt. - Don't include noindexed or redirected URLs. A sitemap full of URLs that shouldn't be indexed sends mixed signals and wastes crawl budget on larger sites.
- Keep your permalink structure stable. Sitemaps reference full URLs directly; changing your permalink structure after a sitemap has already been indexed means submitting the updated sitemap again and expecting a re-crawl period.
- Pair it with broader SEO work. A sitemap helps discovery, but it doesn't substitute for the on-page and technical SEO covered in how to optimize a WordPress website for search engines.
Frequently Asked Questions (FAQ) About XML Sitemaps in WordPress
No, WordPress has generated a basic sitemap automatically since version 5.5 at /wp-sitemap.xml. A plugin like Yoast or Rank Math gives you more control (excluding specific content, image sitemap entries, priority settings) but isn't strictly required for a sitemap to exist.
Check that your permalink structure isn't set to "Plain" under Settings > Permalinks, since the sitemap depends on pretty permalinks being enabled. Also confirm no SEO plugin has disabled the core sitemap via the wp_sitemaps_enabled filter while its own sitemap module is turned off.
Technically nothing stops multiple sitemaps from existing, but you should only submit and rely on one to avoid inconsistent or duplicate data reaching search engines. If you install an SEO plugin, let it disable the core sitemap and use its sitemap exclusively.
It's generated dynamically on request, not as a static file, so it always reflects your current published content the moment it's requested. Search engines still crawl it on their own schedule rather than instantly, so newly published content may take some time to appear as indexed even though it's already in the sitemap.
No, and they shouldn't by default. WordPress's core sitemap and major SEO plugins only include published, publicly visible content. If you ever see unpublished content listed, that's worth investigating as a bug or misconfiguration.
No. A sitemap tells search engines a URL exists and invites them to crawl it, but indexing decisions still depend on content quality, crawl budget, and whether the page meets the search engine's own criteria. Check Search Console's Page Indexing report to see which submitted URLs were actually indexed.
An XML sitemap is built for search engine crawlers and isn't meant to be read by visitors. An HTML sitemap is a regular page on your site listing links for human visitors to navigate. Some sites benefit from having both, but they serve different audiences.
Conclusion
An XML sitemap is one of the simplest technical SEO wins available in WordPress, and in most cases it's already running without you having to do anything: WordPress core has generated one automatically since version 5.5. Adding an SEO plugin like Yoast or Rank Math gives you finer control over what's included, and submitting the sitemap to Google Search Console and Bing Webmaster Tools makes sure both search engines know it's there.
From there, the maintenance is light: keep an eye on the Sitemaps report in Search Console, avoid churning your permalink structure unnecessarily, and treat the sitemap as one piece of a broader SEO setup rather than a fix on its own.


