WPLift is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission.

How to Create a Sitemap in WordPress Without a Plugin (2022)

Last Updated on August 30th, 2022


In this article, we’ll explain exactly how to create a sitemap in WordPress and why is it important to your WordPress site.

Isn’t it true that if you’re a pirate looking for a treasure chest, having a map that shows you exactly where the treasure is going to make your life so much easier?

An XML sitemap essentially does the same thing for search engine crawlers, making it easier for them to find and index pages on your web. Even if your internal linking isn’t great, XML sitemaps will be good for SEO because it enable Google to easily locate your important website pages.

What is an XML Sitemap?

How to Create a Sitemap in WordPress - XML

To find sites on the internet, search engines use crawlers, which are bots that go out into the world wide web to look for them.

Although they’re pretty quick at it, the sheer amount of content available online will make it take a long time for them to find a specific page on your website. This is where an XML sitemap comes in handy!

An XML (Extensible Markup Language) sitemap is a file that contains information about your site’s pages, images, and other files, as well as their relationships. This file is read by search engines like Google to help them crawl your web more intelligently. A sitemap tells Google which pages and files on your site you think are relevant, as well as useful information about these files, such as when the page was last modified, how often it is changed, and any alternate language versions of the page.

When Can a Sitemap Be Used?

A sitemap isn’t needed for everybody. To schedule crawling, Google uses its own complex algorithm.

When does a webmaster need a sitemap, according to Google?

  • Your website is very extensive.
  • Your website is relatively new, with just a few external links pointing to it.
  • Internal ties aren’t established.

In most cases, however, having a sitemap can be helpful in a number of ways.

Why is a Sitemap Important for Your Website?

A sitemap will help your website in general because search engines will regard it as an invitation to crawl and index the pages mentioned. There are two types of sitemaps: HTML and XML, each with its own set of benefits and uses for SEO.

Article Continues Below

However, since the primary purpose of HTML sitemaps is to direct shoppers, we’ll concentrate on the advantages of the XML form, which exists solely to ensure that search engine crawlers find and index the URLs mentioned on a site.

Let’s start with what XML sitemaps don’t do before we get into the details:

  1. The submission of an XML sitemap does not guarantee that the pages will be indexed. The sitemaps are more like a list of URLs that you want the search engines to crawl and index.
  2. The use of XML sitemaps does not increase authority. The URLs described in an XML sitemap, unlike the HTML links on your website, do not pass link authority and have little impact on improving rankings.

Here are the advantages of having a sitemap in your WordPress site:

  • Informs Search Engines About Your Content- An XML sitemap contains details about each page on your site, including when it was generated and last updated, as well as its relevance in relation to other pages on your site.
  • Reduces the number of broken links: Crawl reports can be picked up right away if your site has any broken, incomplete, or incorrect internal links, thanks to sitemaps. Although the issue should be resolved as quickly as possible, sitemaps will include a temporary remedy and assistance in the meantime.
  • The conversion funnel is simplified: It is preferable to have a conversion funnel with a minimum number of steps for the users to convert. The more steps there are, the more likely tourists are to abandon their purchases or registration. Use your sitemap to find out what steps are needed, and combine them where possible. Using a visual representation, such as a flowchart, will help you streamline your funnel.
  • Higher rankings follow content modification: You can only maintain higher search engine rankings if you keep changing the content on your blog, keeping it new and relevant to your visitors’ needs. If you manually created a sitemap or used a sitemap generator, Google will be notified whenever your site’s content is changed.
  • Boosts the start-up of new businesses: The main reason you spend time and money creating new content for your website is that you want to be found by customers online, and using a sitemap can help you get found quickly. It tells search engines about your new pages and when you’ve published a new blog post on your web, which helps them find them. For new websites, this is highly recommended because it jumpstarts activity, interest, and revenue.
  • A time-saving device: News stories, for example, should be distributed while they are still young. You won’t have to wait and wonder when the spiders will come to your website. This time has been drastically reduced by you.
  • Getting to know your visitors: Monitoring your sitemap reports will teach you a lot. You’ll be informed of any bugs, which you’ll be able to correct, as well as where your traffic is coming from and which keywords are driving it. This data will assist you in improving your content and attracting more visits to your website.
  • Bringing together teams: Websites are rarely designed by a single individual, and they often need feedback from various business partners, such as a designer, project manager, or the Smarketing team. A sitemap ensures that everyone involved in the project is on the same page. Since sitemaps are dynamic, they are likely to change as the company grows. The sitemap can be used to keep track of your project’s status, including what’s been finished, what still needs to be done, and how far you’ve come.

What pages does a sitemap contain?

This section of our site-mapping crash course is crucial, so pay attention!

One common misconception is that you must include all of your website pages in a sitemap in order for Google to crawl and index your site. In fact, the situation is reversed. Google doesn’t need to see all of your junk pages; all it needs to know about are the high-quality juicy pages that you believe deserve to be ranked highly. You can ask Google to concentrate on certain pages by adding them in your sitemap. It might or might not take your advice, but that’s another story.

As a general rule, all pages added to a sitemap should be 200 OK pages with high-quality content that is useful to users. That is, you can exclude all pages that do not follow these requirements, with a few exceptions.


404 are deleted pages, so if such pages were removed on purpose, keep them away from your sitemap. The same goes for soft 404 pages that were removed but still return a 200-level success status code. Normally those are pages with little or no content, redirects to the homepage, or 404 pages blocked by robots.txt.


You would want Google to crawl and index a 401 page in some cases. For example, suppose you password-protected a page while it was being developed and then forgot to remove the restrictions when the page went live. Additionally, webmasters can limit access to specific pages in order to protect them from bad bots or spammers.


A 301 answer code indicates that a domain has been permanently redirected to a new address and that the original page has been deactivated. As a result, such pages should be excluded from your XML sitemap. In this case, the only thing to keep in mind is that the sitemap must contain the destination URL.


302 sites have been temporarily redirected. For example, such a redirect is often used in A/B testing, which involves sending a subset of users to a test URL. Since you want to keep the original page indexed in this situation, it should obviously remain in your sitemap.

Article Continues Below

XML sitemap of 5XX pages

The 5XX status codes indicate an issue with your web server. The 503 Service Unavailable error, which indicates that the server is temporarily unavailable, is the most common of the 5xx codes. It’s possible that it happened because the web server was down for maintenance or was overwhelmed.

If the mistake occurred just once, you shouldn’t be concerned because it was most likely caused by routine web server maintenance. If the problem continues, you’ll need to find out what’s causing it and fix it right away, or Google can assume that your website isn’t well-maintained.

It’s not so much a question of whether or not to include 5xx pages in your sitemap, but rather of resolving a problem to ensure that pages have a response code of 200 OK.

Noncanonical pages

Canonical tags aren’t the same as redirecting; they’re more like suggestions than orders, and Google may choose to follow or disregard them. This is why using non-canonical URLs in a sitemap can be perplexing for search engines. If you don’t label a page as canonical, Google will assume you don’t want it indexed. At the same time, you add a page to your sitemap, which encourages people to visit it.

Non-indexable Pages

Every website has a range of utility pages that are useful to users but not to search engines—login pages, pages that appear after signing in, sorting and filtering pages, and so on. The standard practice is to use the robots.txt file to prevent Google from accessing those websites. Alternatively, one might allow Google to crawl the page but restrict indexing with special directives (no index or all).

Both of these pages, of course, should not be included in your sitemap. It not only confuses Google, but it also wastes your crawl budget if a page cannot be indexed but is included in your sitemap. Google won’t be able to crawl any sites that are blocked by robots.txt.

How to Create a Sitemap in WordPress Manually

So you’ve chosen to build a sitemap for your website because you’ve seen the benefits of creating one. How do you go about doing it? A sitemap, as useful as it is, isn’t exactly a simple piece of programming. It’s possible that the logistics of making one would intimidate you. However, this does not discourage you, in this article we listed the step-by-step process to create a sitemap without the use of plugins. 

You are probably wondering, Why would you want to build a sitemap without using any third-party plugins? 

It is simple. All WordPress websites built by the average user should aim to have about ten front-facing plugins to keep them completely functional. Pace, versatility, security, and usability are just a few of the reasons. 

Some plugins that are not safe can leave your website vulnerable; they can also be incompatible with other plugins, causing your website to not load and produce errors; and, finally, some plugins are bulky and overloaded with code, slowing down your website.

Article Continues Below

Oh, and the best part is that it’s really very easy to do if you follow the simple instructions below. So, roll up your sleeves and get to work learning how to make a WordPress Sitemap without the use of a plugin.

1. Open the theme’s functions.php file.

The functions.php file is where you incorporate your WordPress theme’s specific features. It can be used to integrate with WordPress’s core functions, making the theme more flexible, extensible, and efficient. So to start, open functions.php from your theme folder (wp-content/themes/your theme folder/functions.php) in your text editor.

Open Text editor 

How to Create a Sitemap in WordPress - Text Editor

In the right sidebar, Click Function.php

How to Create a Sitemap in WordPress - Function.php

2. Copy and paste the code below into your theme’s function.php file.

/* ------------------------------------------------------------------------- *
* WordPress Dynamic XML Sitemap Without Plugin
* Codes By Emrah Gunduz & All In One SEO
* Updated And Edited By EXEIdeas
/* ------------------------------------------------------------------------- */
add_action("publish_post", "eg_create_sitemap");
add_action("publish_page", "eg_create_sitemap");
function eg_create_sitemap() {
$postsForSitemap = get_posts(array(
'numberposts' => -1,
'orderby' => 'modified',
'post_type' => array('post','page'),
'order' => 'DESC'
$sitemap = '<?xml version="1.0" encoding="UTF-8"?>';
$sitemap .= '<?xml-stylesheet type="text/xsl" href="sitemap-style.xsl"?>';
$sitemap .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach($postsForSitemap as $post) {
$postdate = explode(" ", $post->post_modified);
$sitemap .= '<url>'.
'<loc>'. get_permalink($post->ID) .'</loc>'.
'<lastmod>'. $postdate[0] .'</lastmod>'.
$sitemap .= '</urlset>';
$fp = fopen(ABSPATH . "sitemap.xml", 'w');
fwrite($fp, $sitemap);

3. Now create a file named sitemap-style.XSL.

4. Copy and paste the code below into that file, then save it with the same name.

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="2.0" xmlns:html="http://www.w3.org/TR/REC-html40"xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"><xsl:variable name="fileType"> <xsl:choose> <xsl:when test="//sitemap:url">Sitemap</xsl:when> <xsl:otherwise>SitemapIndex</xsl:otherwise> </xsl:choose> </xsl:variable><html xmlns="http://www.w3.org/1999/xhtml"><head><title><xsl:choose><xsl:when test="$fileType='Sitemap'">Sitemap</xsl:when><xsl:otherwise>Sitemap Index</xsl:otherwise></xsl:choose></title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">body {font-family:Helvetica,Arial,sans-serif;font-size:68.5%;}table {border:none;border-collapse:collapse;}table {font-size:1em;width:100%;}th {text-align:left;padding:5px;}tr.stripe {background-color:#f7f7f7;}</style></head> <body> <div id="content"> <h1>XML Sitemap By EXEIdeas</h1> <div> <p><xsl:choose><xsl:when test="$fileType='Sitemap'"> This sitemap contains <xsl:value-of select="count(sitemap:urlset/sitemap:url)"></xsl:value-of> URLs</xsl:when> <xsl:otherwise>This sitemap index contains <xsl:value-of select="count(sitemap:sitemapindex/sitemap:sitemap)"></xsl:value-of> sitemaps</xsl:otherwise></xsl:choose></p> </div><xsl:choose><xsl:when test="$fileType='Sitemap'"><xsl:call-template name="sitemapTable"/></xsl:when> <xsl:otherwise><xsl:call-template name="siteindexTable"/></xsl:otherwise></xsl:choose> </div> </body> </html> </xsl:template> <xsl:template name="siteindexTable"> <table cellpadding="3"><thead><tr><th width="50%">URL</th><th>LastChange</th></tr></thead><tbody><xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/><xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/><xsl:for-each select="sitemap:sitemapindex/sitemap:sitemap"><tr><xsl:if test="position() mod 2 != 1"><xsl:attribute name="class">stripe</xsl:attribute></xsl:if><td><xsl:variable name="itemURL"><xsl:value-of select="sitemap:loc"/></xsl:variable><a href="{$itemURL}"><xsl:value-of select="sitemap:loc"/></a></td><td><xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/></td></tr></xsl:for-each></tbody></table> </xsl:template> <xsl:template name="sitemapTable"><table cellpadding="3"><thead><tr><th width="50%">URL</th><th>Priority</th><th>Change Frequency</th><th>LastChange</th></tr></thead><tbody><xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/><xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/><xsl:for-each select="sitemap:urlset/sitemap:url"><tr><xsl:if test="position() mod 2 != 1"><xsl:attribute name="class">stripe</xsl:attribute></xsl:if><td><xsl:variable name="itemURL"><xsl:value-of select="sitemap:loc"/></xsl:variable><a href="{$itemURL}"><xsl:value-of select="sitemap:loc"/></a></td><td><xsl:if test="string(number(sitemap:priority))!='NaN'"><xsl:value-of select="concat(sitemap:priority*100,'%')"/></xsl:if></td><td><xsl:value-of select="concat(translate(substring(sitemap:changefreq, 1, 1),concat($lower, $upper),concat($upper, $lower)),substring(sitemap:changefreq, 2))"/></td><td><xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/></td></tr></xsl:for-each></tbody></table> </xsl:template></xsl:stylesheet>

5. Create a new post or update an existing one.

Now that you’ve added a new page or post to your blog, this code will delete the old content and replace it with new content in the original file. Check the sitemap at www.mydomain.com/sitemap.xml, where you’ll find a modified XML sitemap.

Submit XML Sitemap to Google

You can send the XML sitemap URLs to search engines like Google or Bing once they’ve been created.

Before we begin, verify the website’s owner via Google Search Console and upload your sitemap to Google.

  1. When you’re done, go to Google Search Console and look for your website.
  2. To use the sitemaps, go to Index -> Sitemaps.
  3. Click Submit after entering your WordPress sitemap URL.
How to Create a Sitemap in WordPress - Sitemap
  1. Enable Google to process your submission and crawl your pages for a few days.
How to Create a Sitemap in WordPress - Webmaster Tools

Wrapping It Up

We hope that this guide helped you learn how to create a sitemap in WordPress. As previously mentioned, incorporating a sitemap into your website would only help it. Since there are no known threats, you would not be penalized by Google if you have one. It is the most advantageous of the sitemap benefits. 

You should have a sitemap on your website if you want to improve your rankings and provide your users with a better and more satisfying experience. After all, what do you have to lose if there are no defined threats or penalties in using a sitemap?

Thanks for sticking with us on this one! We’ll see you soon! :)

Would you like to learn more about WordPress?

Sign up for our Weekly WordPress Newsletter.

Every Friday you’ll receive news, tutorials, reviews, and great deals from the WordPress space.

Invalid email address
A team of WordPress experts that love to test out new WordPress related software, WordPress plugins and WordPress themes.