How to Create XML Sitemaps in WordPress for Better Indexing

XML sitemaps help search engines discover and index WordPress content efficiently. These structured files list all important URLs, guiding crawlers to fresh content and indicating update priorities. This comprehensive guide teaches XML sitemap creation, optimization, submission to search engines, and troubleshooting for maximum indexing efficiency.

What Is an XML Sitemap

XML sitemaps are machine-readable files listing website URLs with metadata about content freshness, update frequency, and relative importance. Search engines use sitemaps to discover pages, especially on large sites or sites with poor internal linking.

Basic XML Sitemap Structure:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://example.com/page/</loc>
    <lastmod>2025-01-15</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.8</priority>
  </url>
</urlset>

Why XML Sitemaps Matter for SEO

Faster Indexing: New content discovered within hours instead of days.

Complete Coverage: Ensures all important pages indexed, especially those with few backlinks.

Crawl Efficiency: Guides search bots to updated content first.

Large Site Management: Critical for sites with 100+ pages.

Content Prioritization: Indicates which pages matter most.

WordPress Default Sitemap (WordPress 5.5+)

WordPress generates basic XML sitemaps automatically since version 5.5.

Access Default Sitemap:

https://yoursite.com/wp-sitemap.xml

Sitemap Index Structure:

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

Limitations:

  • Basic functionality only
  • No priority or change frequency
  • Limited customization options
  • No advanced features

Creating Advanced Sitemaps with Yoast SEO

Yoast SEO provides more comprehensive sitemap functionality.

Enabling Yoast Sitemap:

  1. Install Yoast SEO plugin
  2. Navigate to SEO → General → Features
  3. Enable XML sitemaps
  4. Access sitemap at: yoursite.com/sitemap_index.xml

Yoast Sitemap Features:

  • Automatic updates
  • Excluded content types
  • Custom post type inclusion
  • Taxonomy sitemaps
  • Image sitemaps
  • News sitemaps (premium)

Configuring Yoast Sitemap:

  1. Go to SEO → Search Appearance
  2. Select content type (Posts, Pages, etc.)
  3. Toggle “Show in search results”
  4. Set noindex for unwanted content

Creating Sitemaps with Rank Math

Rank Math offers similar advanced sitemap features.

Enabling Rank Math Sitemap:

  1. Install Rank Math plugin
  2. Navigate to Rank Math → Sitemap Settings
  3. Enable sitemaps
  4. Access at: yoursite.com/sitemap_index.xml

Rank Math Features:

  • Automatic generation
  • Exclude specific URLs
  • Ping search engines on update
  • Author/date archive inclusion
  • Custom sitemap links

Manual XML Sitemap Creation

For custom requirements, generate sitemaps programmatically.

Simple Sitemap Function:

function dprt_generate_sitemap() {
    $posts = get_posts(array(
        'post_type' => 'post',
        'post_status' => 'publish',
        'numberposts' => -1,
        'orderby' => 'modified',
    ));

    $sitemap = '<?xml version="1.0" encoding="UTF-8"?>';
    $sitemap .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

    foreach ($posts as $post) {
        $sitemap .= '<url>';
        $sitemap .= '<loc>' . get_permalink($post->ID) . '</loc>';
        $sitemap .= '<lastmod>' . get_the_modified_date('c', $post->ID) . '</lastmod>';
        $sitemap .= '<changefreq>weekly</changefreq>';
        $sitemap .= '<priority>0.8</priority>';
        $sitemap .= '</url>';
    }

    $sitemap .= '</urlset>';

    file_put_contents(ABSPATH . 'sitemap.xml', $sitemap);
}

// Generate sitemap when post published/updated
add_action('save_post', 'dprt_generate_sitemap');

Sitemap Best Practices

1. Include Only Indexable URLs

Exclude:

  • Duplicate content
  • Noindexed pages
  • Login/admin pages
  • Thank you pages
  • Cart/checkout pages

2. Keep Under 50,000 URLs

Split large sitemaps into multiple files.

Sitemap Index Example:

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>https://example.com/sitemap-posts.xml</loc>
    <lastmod>2025-01-15</lastmod>
  </sitemap>
  <sitemap>
    <loc>https://example.com/sitemap-pages.xml</loc>
    <lastmod>2025-01-10</lastmod>
  </sitemap>
</sitemapindex>

3. Keep File Size Under 50MB

Compress large sitemaps with gzip.

4. Update Regularly

Regenerate when content published or updated.

5. Use Accurate lastmod Dates

Helps search engines prioritize crawling fresh content.

Submitting Sitemap to Google

Google Search Console:

  1. Log into search.google.com/search-console
  2. Select property
  3. Navigate to Sitemaps (left menu)
  4. Enter sitemap URL: sitemap_index.xml
  5. Click Submit

Verify Submission: Check “Discovered” and “Submitted” URL counts match expectations.

Automatic Ping (optional):

function dprt_ping_google($post_id) {
    if (get_post_status($post_id) == 'publish') {
        $sitemap_url = urlencode(home_url('/sitemap_index.xml'));
        wp_remote_get('http://www.google.com/ping?sitemap=' . $sitemap_url);
    }
}
add_action('publish_post', 'dprt_ping_google');

Submitting to Other Search Engines

Bing Webmaster Tools:

  1. Visit bing.com/webmasters
  2. Add site
  3. Navigate to Sitemaps
  4. Submit sitemap URL

Yandex Webmaster:

  1. Visit webmaster.yandex.com
  2. Add site
  3. Go to Indexing → Sitemap files
  4. Add sitemap URL

Image Sitemaps

Help Google discover and index images.

Image Sitemap Structure:

<url>
  <loc>https://example.com/post-with-images/</loc>
  <image:image>
    <image:loc>https://example.com/image.jpg</image:loc>
    <image:caption>Image caption here</image:caption>
    <image:title>Image title</image:title>
  </image:image>
</url>

Yoast SEO automatically includes images in sitemaps.

Video Sitemaps

Enhance video content discovery.

Video Sitemap Example:

<url>
  <loc>https://example.com/video-post/</loc>
  <video:video>
    <video:thumbnail_loc>https://example.com/thumb.jpg</video:thumbnail_loc>
    <video:title>Video Title</video:title>
    <video:description>Video description</video:description>
    <video:content_loc>https://example.com/video.mp4</video:content_loc>
    <video:duration>600</video:duration>
  </video:video>
</url>

Excluding URLs from Sitemap

Yoast SEO – Individual Posts:

  1. Edit post/page
  2. Scroll to Yoast meta box
  3. Advanced tab
  4. Set “Allow search engines to show this Post in search results?” to No

Yoast SEO – Entire Post Types: SEO → Search Appearance → Content Types → Toggle off

Rank Math – Individual Posts: Rank Math meta box → Advanced → Robots Meta → Select noindex

Manual Exclusion:

add_filter('wpseo_sitemap_exclude_post_type', function($excluded, $post_type) {
    if ($post_type === 'custom_post_type') {
        return true;
    }
    return $excluded;
}, 10, 2);

WooCommerce Sitemaps

E-commerce sites require careful sitemap configuration.

Include:

  • Product pages (in stock)
  • Product categories
  • Main shop page

Exclude:

  • Out of stock products
  • Cart/checkout pages
  • My account pages
  • Order confirmation pages

Yoast WooCommerce SEO (addon): Automatically optimizes WooCommerce sitemaps.

Multilingual Sitemaps

For multilingual sites (WPML, Polylang, etc.).

Hreflang in Sitemaps:

<url>
  <loc>https://example.com/page/</loc>
  <xhtml:link rel="alternate" hreflang="en" href="https://example.com/page/" />
  <xhtml:link rel="alternate" hreflang="es" href="https://example.es/pagina/" />
  <xhtml:link rel="alternate" hreflang="fr" href="https://example.fr/page/" />
</url>

WPML and Polylang automatically generate language-specific sitemaps.

Troubleshooting Sitemap Issues

Sitemap Not Found (404):

  • Flush permalinks: Settings → Permalinks → Save
  • Check plugin conflicts
  • Verify .htaccess rules

Duplicate Sitemaps: Disable WordPress core sitemap if using plugin:

add_filter('wp_sitemaps_enabled', '__return_false');

Sitemap Not Updating:

  • Clear caching plugins
  • Regenerate sitemap manually
  • Check file permissions

Crawl Errors in Search Console:

  • Review excluded URLs
  • Fix broken internal links
  • Remove deleted pages from sitemap

Monitoring Sitemap Performance

Google Search Console Insights:

  1. Navigate to Sitemaps report
  2. Check submitted vs. indexed URLs
  3. Investigate discrepancies
  4. Monitor error reports

Expected Indexing:

  • Small sites (under 100 pages): 80-100% indexed
  • Medium sites (100-1,000): 70-90% indexed
  • Large sites (1,000+): 60-80% indexed

Advanced Sitemap Optimizations

Priority Values:

  • Homepage: 1.0
  • Main category pages: 0.8
  • Blog posts: 0.6
  • Tag archives: 0.4

Change Frequency:

  • News sites: daily
  • Blogs: weekly
  • Static pages: monthly
  • Archived content: yearly

Custom Sitemap Routes:

add_action('init', function() {
    add_rewrite_rule(
        'custom-sitemap\.xml$',
        'index.php?custom_sitemap=1',
        'top'
    );
});

add_filter('query_vars', function($vars) {
    $vars[] = 'custom_sitemap';
    return $vars;
});

add_action('template_redirect', function() {
    if (get_query_var('custom_sitemap')) {
        header('Content-Type: application/xml');
        // Generate custom sitemap
        exit;
    }
});

Sitemap Caching

Cache sitemaps for performance.

Cache Sitemap Output:

function dprt_cached_sitemap() {
    $cached = get_transient('dprt_sitemap_cache');
    if ($cached) {
        return $cached;
    }

    // Generate sitemap
    $sitemap = dprt_generate_sitemap();

    set_transient('dprt_sitemap_cache', $sitemap, 12 * HOUR_IN_SECONDS);
    return $sitemap;
}

Conclusion

WordPress XML sitemaps improve search engine indexing through structured URL lists, metadata about content freshness, and efficient crawl guidance. Use Yoast SEO or Rank Math for comprehensive sitemap management, submit to Google Search Console and Bing Webmaster Tools, exclude non-indexable content, and monitor performance regularly. Proper sitemap implementation ensures all valuable content gets discovered and indexed efficiently.

  1. Google Search Console
  2. XML Sitemap Protocol
  3. Yoast SEO Plugin
  4. Rank Math SEO
  5. Bing Webmaster Tools

Call to Action

SEO configurations need protection. Backup Copilot Pro safeguards your WordPress sitemap settings and SEO data. Protect your indexing optimizations—start your free 30-day trial today!