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

The Ultimate Guide to Creating Sitemap in WordPress Without Using a Plugin

Last Updated on January 4th, 2024

Tags:

Imagine you’re a pirate looking for a treasure chest; having a map showing where the treasure is located would make your life much easier.

Similarly, if you have a website on WordPress, you want the content to be easily found by search engines. 

Thankfully, an XML sitemap does the same 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 they enable Google to locate your essential website pages. It leads to better visibility and ranking in the search engines.

If you also want to create an XML sitemap for your WordPress site, you have reached the right place. 

In this blog, we will explain how to create a sitemap for a WordPress website without a plugin. Here is the list of things we will look at in this blog.

  • What is an XML sitemap?
  • When Can a Sitemap Be Used?
  • Why is a Sitemap Important for Your Website?
  • What pages does a sitemap contain?
  • How to Create a Sitemap in WordPress Manually?

Without further ado, let’s start.

What is an XML Sitemap?

what is an xml sitemap?

For finding sites on the internet, search engines use crawlers, which are nothing but bots that go out into the world wide web to look for pages and posts that contain information.

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, defined priority by the console manager, how often it is changed, and any alternate language versions of the page.

Article Continues Below

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 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.

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. Unlike the HTML links on your website, the URLs described in an XML sitemap do not pass link authority and have little impact on improving rankings.

Here are the advantages of having a WordPress website sitemap:

  • 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 users 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 create 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 visit 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 marketing 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 your website pages in a sitemap for Google to crawl and index your site. However, the situation is reversed. Google doesn’t need to see all your junk pages; all it needs to know about are the high-quality, juicy pages you believe deserve to be ranked highly. 

By doing this, you can ask Google to concentrate on specific pages by adding them to your sitemap. It might or might not take your advice, but that’s another story.

Article Continues Below

As a general rule, all pages added to a sitemap should be 200 OK pages with high-quality, and valuable content for users. You can exclude all pages that do not follow these requirements, with a few exceptions.

Here is the list of things you should and should not have on different pages in your WordPress site.

4XX ITEMS YOU SHOULDN’T HAVE IN YOUR SITEMAP

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.

4XX ITEMS THAT MAY BE REQUIRED IN YOUR SITEMAP

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.

3XX ITEMS YOU SHOULDN’T HAVE IN YOUR SITEMAP

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.

3XX ITEMS YOU MAY REQUIRE FOR YOUR SITEMAP

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.

XML sitemap of 5XX pages

The 5XX status codes indicate an issue with your web server. The 503 Service Unavailable error, indicates that the server is temporarily unavailable, and is the most common of the 5xx codes.

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. That is why using non-canonical URLs in a sitemap can be perplexing for search engines.

Article Continues Below

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, encouraging 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 confuses Google and wastes your crawl budget if a page cannot be indexed despite being included in your sitemap. Google won’t be able to crawl any sites 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 precisely a simple piece of programming. It’s possible that the logistics of making one would intimidate you. However, this does not discourage you; here, we have listed the step-by-step process to Create WordPress XML sitemap without plugin. 

You are probably wondering, Why do 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 not to load and produce errors; and, finally, some plugins are bulky and overloaded with code, slowing down your website.

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 learn how to create a sitemap for a WordPress website without using 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 

open text editor to creating sitemap in wordpress without using a plugin

In the right sidebar, Click Function.php

function.php for creating sitemap in wordpress without using a plugin

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) {
setup_postdata($post);
$postdate = explode(" ", $post->post_modified);
$sitemap .= '<url>'.
'<loc>'. get_permalink($post->ID) .'</loc>'.
'<priority>1</priority>'.
'<lastmod>'. $postdate[0] .'</lastmod>'.
'<changefreq>daily</changefreq>'.
'</url>';
}
$sitemap .= '</urlset>';
$fp = fopen(ABSPATH . "sitemap.xml", 'w');
fwrite($fp, $sitemap);
fclose($fp);
}

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.

How to Create an XML Sitemap with FTP

You can create an XML sitemap with an FTP application if you don’t want to use the Theme Editor. The process is similar in both cases as it involves inserting code into the functions.php file. 

Don’t forget to create a child theme before you make any changes to this file. Doing so will enable you to revert to your site’s old version if you encounter a problem. 

In case you’re not currently using an FTP client, you’ll have to install it on your computer and connect it to your site’s server. When done, you should follow the steps below:

  • Navigate to the site’s wp-content folder using the FTP client
  • Find the Themes folder and open the folder that contains the files of the theme you’re currently using 
  • Locate the functions.php file and right-click on it
  • Choose the View/Edit option from the menu
  • Paste the code we provided above after the text editor pops up on the screen 
  • Click Save 

Writing your own code will provide you with a higher degree of freedom since you’ll have control over the functionalities you want the XML sitemap you’re creating to have.

Creating an XML Sitemaps with Third-Party Tools

Adding code to theme files isn’t the only way to create an XML sitemap without a plugin for your site. Several online tools like the XML Sitemap Generator or XML-Sitemaps.com let you create XML sitemaps for your site. Hence, there’s no need to install a plugin that could affect your site’s speed.

That said, these tools are best suited for small websites, so they may not be the right solution for you if you’re managing a site with more than 500 pages. 

The process of creating a new sitemap with these tools is straightforward. You just have to provide a site’s address, set a modified date, choose the change frequency, and adjust a few other settings before clicking the Generate Sitemap button. 

However, the process isn’t instant, and you’ll have to wait a while for the platform to send you the XML sitemap file. Once you have the file, you should use the FTP client to upload it to your site’s server and take steps to submit it to Google or some other search engine.

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.
submit xml sitemap to google
  1. Enable Google to process your submission and crawl your pages for a few days.
submit xml sitemap to bing

Updating an XML Sitemap

Manually creating and submitting an XML is only half the work, especially if you opt to submit it to a search engine while your site is relatively new. 

Updating an XML sitemap is the other, arguably more important half, of the work you’ll have to do to keep your website in Google’s or Bing’s good graces. New pages you add to a website won’t be included in the sitemap meaning crawlers will need time to index them. 

If you decide to create an XML sitemap on your own, you’ll also be responsible for keeping it up to date. So, whenever you alter content on an existing page or add new elements, you’ll also have to update the sitemap. 

The solution to this problem is to manually create a dynamic XML sitemap that updates automatically whenever you publish new content you want a search engine to see. However, this can be an overwhelming task even for an experienced coder. That’s why most website admins use SEO plugins, like Yoast SEO that enable them to update XML sitemaps automatically.

Wrapping Up

We hope this guide helped you learn how to create a WordPress sitemap without plugins. There are no known threats, and Google would not penalize you if you don’t have a sitemap. 

However, having a sitemap for your website helps you improve your rankings and provide your users a better and more satisfying experience. Go ahead and create a sitemap for your WordPress site right away.

Frequently Asked Questions about Creating Sitemaps for WordPress Sites without Plugins?

How Do I Add a Sitemap to WordPress without Plugins?

All versions of WordPress released after the 5.5 update contain XML sitemaps. So, chances are that your website already has an XML sitemap if you’re using the latest version of WordPress. 

You can check if WordPress automatically generated an XML sitemap for your site by navigating to http://yourwebsite.com/sitemap.hml in your web browser. 

WordPress generates sitemaps containing all your site’s pages, so admins often modify or replace them with a new XML sitemap. The quickest way to create a sitemap without a plugin is to use an online tool.

How Do I Manually Create a Sitemap in WordPress?

In theory, creating a sitemap manually seems simple, as you just have to complete a few steps before you’re ready to submit it to a search engine. The practical side of making an XML sitemap from scratch is far more complex, especially if you don’t want the sitemap to be static. 

The process starts with opening the WordPress theme editor and using it to access a theme’s functions.php file. The tricky part is writing the code since each functionality you want the sitemap to have must be clearly defined in the code you insert into the functions.php file. 

How to Create an HTML Sitemap in WordPress without a Plugin?

Although they’re not as beneficial for a site’s SEO as XML sitemaps, HTML sitemaps are still useful as they allow your site’s visitors to quickly find links to different pages or posts on your website. 

Before you start working on a new HTML sitemap, you first have to create a child theme. Afterward, you must make a ‘partials’ folder within the child theme folder and then create a sitemap.php file. 

You can then add code to this file, but keep in mind that the code you find online may not work on your site. The final step involves ensuring the HTML sitemap you created is visible on your website’s frontend.  

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