XML sitemaps simply turned 18 in June, and in honor of its full-fledged introduction into maturity, I’m breaking down how XML sitemaps work, methods to construct one, and why XML sitemaps provide a boatload of SEO advantages.
What’s an XML sitemap?
In a nutshell, an XML sitemap is a protocol in XML format that tells search engines like google concerning the URLs on an internet site accessible to crawl.
XML sitemaps have been meant to share details about every URL, like:
- When it was final up to date.
- How usually it modifications.
- How vital it’s in relation to different URLs throughout your web site.
XML sitemaps permit search engines like google to crawl your web site extra effectively if sure URLs are remoted.
If you happen to’re an search engine optimisation skilled, you in all probability already use XML sitemaps constructed into your Yoast WordPress plugin. However there are many extras that you simply is perhaps lacking.
Find out how to construct a dynamic XML sitemap
If you happen to’re utilizing WordPress, leverage search engine optimisation plugins like Yoast and RankMath to generate a dynamic XML sitemap.
If you happen to’re not utilizing WordPress, comply with these steps to construct a dynamic XML sitemap.
Perceive your navigational construction
Pull collectively a listing of all our URLs on the web site and group them to align to navigational construction and content material groupings.
Companion together with your developer group
Share the checklist of URLs grouped collectively together with your dev group to achieve their assist in making a dynamic XML sitemap utilizing Python, PHP, or JavaScript.
Right here is an instance of methods to code a dynamic XML sitemap utilizing Python:
import xml.etree.ElementTree as ET
import datetime
# Listing of URLs (substitute these together with your precise URLs)
urls = [
"https://www.example.com/page1",
"https://www.example.com/page2",
"https://www.example.com/page3",
# Add more URLs here
]
# Create the foundation aspect
urlset = ET.Factor("urlset")
urlset.set("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")
# Loop by URLs and create URL entries
for url in urls:
url_elem = ET.SubElement(urlset, "url")
loc_elem = ET.SubElement(url_elem, "loc")
loc_elem.textual content = url
lastmod_elem = ET.SubElement(url_elem, "lastmod")
lastmod_elem.textual content = datetime.datetime.now().isoformat()
changefreq_elem = ET.SubElement(url_elem, "changefreq")
changefreq_elem.textual content = "day by day" # You'll be able to set this to the specified frequency
priority_elem = ET.SubElement(url_elem, "precedence")
priority_elem.textual content = "0.5" # You'll be able to set this to a price between 0 and 1
# Create the XML tree
tree = ET.ElementTree(urlset)
# Save the XML to a file
tree.write("sitemap.xml", encoding="utf-8", xml_declaration=True)
When working with builders, I’ve leveraged Flask and Python collectively to create a really dynamic XML sitemap that modifications every time the web site’s content material modifications.
If we are able to outline the dynamic sitemap route primarily based on the web site’s content material utilizing a perform like get_dynamic_urls()
, we should always be capable of retrieve all URLs.
@app.route('/sitemap.xml', strategies=['GET'])
def sitemap():
urls = get_dynamic_urls() # Substitute together with your dynamic URL retrieval logic
urlset = ET.Factor("urlset")
urlset.set("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")
for url in urls:
url_elem = ET.SubElement(urlset, "url")
loc_elem = ET.SubElement(url_elem, "loc")
loc_elem.textual content = url
lastmod_elem = ET.SubElement(url_elem, "lastmod")
lastmod_elem.textual content = datetime.datetime.now().isoformat()
changefreq_elem = ET.SubElement(url_elem, "changefreq")
changefreq_elem.textual content = "day by day"
priority_elem = ET.SubElement(url_elem, "precedence")
priority_elem.textual content = "0.5"
xml_content = ET.tostring(urlset, encoding="utf-8")
return xml_content, {'Content material-Sort': 'utility/xml'}
If you happen to’re sharing code throughout a number of area properties, make sure the information are coded correctly in your HTML pages.
For instance, your CSS and JavaScript information ought to be linked utilizing <hyperlink>
and <script>
tags.
Earlier than sharing the code throughout completely different domains, you’ll have to create a centralized server to host the shared XML sitemap guidelines.
You’ll have a number of phases of your dynamic XML sitemap together with your builders till all the principles get confirmed.
Don’t overlook to test the dynamic URLs are literally getting retrieved and built-in into your sitemap logic.
Add to your server
As soon as your XML sitemap is compressed, add your dynamic XML sitemap to your web site’s root listing.
Undergo search engines like google
Let search engines like google find out about your XML sitemaps by submitting them by Google Search Console and Bing Webmaster Instruments.
Ongoing upkeep
An XML sitemap is not only a “set it and overlook it” search engine optimisation tactic. It’s important to replace your XML sitemap as your web site modifications.
15 suggestions to bear in mind when constructing an XML sitemap
1. XML sitemaps aren’t a rating issue
When requested on X (beforehand Twitter) if there’s a ranking advantage to using XML sitemaps, Google’s Gary Illyes responded:
- “No, not direct anyway.”
2. Google can discover your pages with no sitemap
Websites don’t need a sitemap if they are small and linked correctly, Daniel Waisberg, Search Advocate at Google, shared in a Google Search Console coaching video.
Nonetheless, he adopted up by saying a sitemap is perhaps particularly useful if:
- The positioning is absolutely giant.
- The positioning’s pages are remoted.
- The positioning is new or modifications rapidly.


Additionally, it’s vital to notice that Google’s John Muller stated on X (beforehand Twitter) that having an XML sitemap is a “minimal baseline for any critical web site.”
3. Google checks to see in case your XML sitemap has modified earlier than reprocessing
Google does test to see in case your XML sitemap has modified earlier than it wastes sources parsing and processing the file once more, Illyes confirmed.
He stated in an SEO Office Hours.
- “As quickly as you modify one thing in your sitemap, be that the URL aspect or final mod, the sitemap will likely be parsed once more and usually reprocessed. That doesn’t imply that the URLs will likely be absolutely crawled after all they’re nonetheless topic to the standard evaluations like another URL. It’s additionally price to say that in case you take away a URL from the sitemap as a result of maybe it doesn’t exist anymore that doesn’t imply it’s routinely going to be dropped from the index and even prioritized for crawling so it may be dropped sooner.”
4. XML sitemaps can get your new content material listed faster
Mueller confirmed that telling Google your XML sitemap is up to date will help get your new content material listed faster.
He shared:
- “Pinging a sitemap is a bit completely different than simply offering it within the robots.txt — by pinging, you’re actively flagging a change within the sitemap file. If you happen to’re eager on having new content material listed rapidly, that’s follow.”
5. XML sitemaps have to be UTF-8 encoded
In case your XML sitemap isn’t utilizing UTF-8, search engines like google can’t learn it.
6. Hold the file dimension beneath 50 MB (uncompressed) or 50,000 URLs
There are dimension limits to your XML sitemaps. Hold it beneath 50,000 URLs per sitemap or 50 MB (uncompressed).
When you have a bigger file dimension or extra URLs, use a number of XML sitemaps.
7. You’ll be able to have a number of XML sitemaps
Google allows you to submit multiple sitemaps. Splitting up your sitemaps into completely different sections of your web site to measure efficiency will be helpful.
For instance, in case you’re a big ecommerce web site, you may section your XML sitemaps by product kind (i.e., ladies’s footwear vs. males’s footwear).
Or, you probably have a number of languages, it’s your decision an hreflang associated to your <loc> XML sitemap.
When you have alternate languages, it doesn’t rely towards the 50,000 URL max.
Or, you probably have numerous movies or photos, you possibly can separate your XML sitemaps right into a video XML sitemap and a picture XML sitemap.
There isn’t any rank profit to having a number of XML sitemaps.
8. When you have a number of XML sitemaps, keep in mind to make use of a sitemap index file
When you have a number of XML sitemaps for a big web site, you’ll wish to submit a sitemap index file to submit many sitemaps directly.
9. The lastmod tag ought to be flawless
The <lastmod>
tag is likely one of the most important components of your XML sitemap.
As an illustration, my structured information leverages the <lastmod> date of my XML sitemap.
The <lastmod>
tag additionally indicators to search engines like google whether or not you’ve refreshed previous content material or launched new content material.
Mueller confirmed this by stating:
- “…If you happen to’re simply altering the timestamp footer, certain, the web page has technically modified too, however ought to that be prioritized – in all probability not.”
Bing has even made an official stance on the lastmod
tag in XML sitemap, stating:
- “For XML sitemaps, one of the crucial essential tags you may embody in your sitemap is the “lastmod” tag.”
10. XML sitemaps ought to solely embody 200 standing URLs which are all self-canonicalized
Bear in mind to maintain solely stay URLs, 200 standing, indexable and self-canonicalized.
If you happen to proceed to showcase 404 or 301 redirected pages, search engines like google may cease crawling your XML sitemap solely.
Mueller responded to a touch upon X (previously referred to as Twitter):
- “We’d cease fetching sitemap information if the URLs are invalid, however in case you’re returning content material or redirecting (which is kinda really helpful), we’ll maintain attempting them. It shouldn’t trigger issues, since total sitemap information are solely a tiny-tiny a part of all URLs fetched from a web site.”
11. Search engines like google can test your XML sitemap day by day
Fabrice Canel from Microsoft shared that Microsoft checks your XML sitemap daily.
Whereas Mueller shared that Google checks your XML sitemap based on frequency (a.ok.a., your <lastmod>
tag).
12. Web page pace not directly impacts your XML sitemap
Everyone knows how very important web page pace is to our search engine optimisation efforts. However how does a slow-performing web site impression your XML sitemap?
Mueller has confirmed page speed should not impact your XML sitemap by stating:
- “So long as it doesn’t day trip, try to be advantageous. Perhaps cache the most recent model to forestall pointless server load?”
The reality is, I’ve labored on slow-performing web sites the place the XML sitemap will not be loading when search engines like google crawl the web site inflicting main rating fluctuations.
There may be an oblique impression in your XML sitemap in case your web site doesn’t load correctly.
Because of this it’s vital to make use of Gzip compression to cut back file dimension and pace up loading instances.
13. Take away <precedence> tag out of your XML sitemaps
Illyes in contrast the <precedence>
tag in XML sitemaps to “a bag of noise.”
So in case you’re relying on search engines like google to crawl your URLs in your XML sitemap primarily based on precedence, you’ll be ready a very long time.
I like to recommend eradicating this tag out of your XML sitemaps.
14. When you have navigational construction points, pair your XML sitemap with an HTML sitemap
There have all the time been combined emotions about HTML sitemaps.
Mueller shared that HTML sitemaps “should never be needed.”
He continued:
- “I modified my thoughts on HTML sitemaps through the years, they need to by no means be wanted. Websites small & giant ought to all the time have a transparent navigational construction. If you happen to really feel the necessity for a HTML sitemap, spend the time enhancing your web site’s structure as an alternative. HTML sitemaps match into the identical bin with HTML loading spinners.”
<iframe src="https://mastodon.social/@johnmu/109477617298107922/embed" class="mastodon-embed" fashion="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script src="https://mastodon.social/embed.js" async="async"></script>
When engaged on giant web sites at an enterprise stage, there are sometimes a number of layers of decision-makers on an internet site navigation construction. And oftentimes, search engine optimisation greatest practices are considered.
I pair each my XML sitemap with an HTML sitemap till I’m assured in our web site navigation and inside linking hierarchy.
15. Don’t overlook to incorporate all of your XML sitemaps in your robots.txt file
Don’t overlook to incorporate your XML sitemaps (all of them) as hyperlinks in your robots.txt file.
Right here is an instance:


Don’t fear about the place within the robots.txt file these ought to go. There may be no impact on the location of your XML sitemap in your robots.txt file.
Mueller confirmed this:
XML sitemaps are the blueprint of your web site for search engines like google
Whether or not you’re launching a brand new webpage or simply including a canonical tag to a replica web page, your XML sitemap is one thing you must replace 24/7.
However accomplish that with warning.
Whilst you shouldn’t be paranoid, your XML sitemap is the blueprint of your own home for search engines like google.
So don’t overlook to submit your XML sitemaps to Google Search Console and Bing Webmaster Instruments.
Opinions expressed on this article are these of the visitor creator and never essentially Search Engine Land. Employees authors are listed here.