Contents
Introduction
In the world of search engine optimization, an XML sitemap acts as a roadmap for crawlers, guiding them to all important pages, images and video resources on your site. WordPress, by default, generates a basic XML sitemap as of version 5.5, but you may want to create and customize your sitemap for finer control over indexing. This article dives into everything you need to know: from the fundamentals of sitemaps and built‐in capabilities to advanced plugin solutions and code‐level tweaks.
What is an XML Sitemap
An XML sitemap is a file (usually named sitemap.xml
) that lists URLs for a site alongside additional metadata such as last modification date, change frequency, and priority. Search engine bots use this file to understand the structure and freshness of your content.
Why Sitemaps Are Important for SEO
- Comprehensive Indexing: Ensures that no pages are missed, especially new or orphaned pages.
- Priority Hints: You can suggest which pages are most important.
- Media Inclusion: Support for images, videos or news enhances discovery of rich media.
- Error Tracking: Search Console reports on sitemap issues, enabling quick fixes.
Generating an XML Sitemap in WordPress
1. Built‐In WordPress Sitemap
Since WordPress 5.5, a default sitemap is available at https://yourdomain.com/wp-sitemap.xml
. No plugin required. It covers posts, pages, categories, tags and custom taxonomies.
For more details, refer to the official guide: WordPress XML Sitemaps.
2. Using Popular Plugins
- Yoast SEO: Automatic sitemaps with advanced settings. Learn more.
- All in One SEO: Supports images, video sitemaps and sitemap indexing. Learn more.
- Google XML Sitemaps: Classic plugin focused purely on sitemaps, with granular options.
Customizing Your XML Sitemap
Out‐of‐the‐box sitemaps are useful, but you may need to:
- Exclude certain post types or taxonomies
- Split large sitemaps into chunks
- Add image/video tags
- Change URL patterns or filename
1. Excluding Post Types and Taxonomies
Add this to your theme’s functions.php
or a site‐specific plugin:
add_filter(wp_sitemaps_post_types, function(post_types) {
unset(post_types[attachment]) // Exclude attachments
unset(post_types[your_custom_post_type])
return post_types
})
2. Limiting URLs per Sitemap
By default, WordPress splits sitemaps every 1,000 items. You can adjust this:
add_filter(wp_sitemaps_max_urls, function(max) {
return 500 // Smaller chunks
})
3. Including Images in Your Sitemap
For image‐rich sites, enable the image sitemap feature:
add_filter(wp_sitemaps_add_images, __return_true)
4. Customizing the Sitemap Index Filename
If you must change the default wp-sitemap.xml
, use rewrite rules or a plugin filter. Example (advanced):
// Advanced: custom rewrite to serve sitemap-index.xml
add_action(init, function() {
add_rewrite_rule(^sitemap-index.xml
Acepto donaciones de BAT's mediante el navegador Brave :)