As of version 5.5, WordPress automatically generates an XML sitemap for your site’s content. The sitemap benefits your site by providing a simple “map” of all posts, pages, categories, tags, and more. This is useful for bots and humans, and is considered beneficial for SEO and even GEO. Even better, WordPress makes it easy to customize your sitemap as desired. For example, if you want to include or exclude certain pages, or even disable the WP sitemap completely, there are programmatic techniques (i.e., code snippets) for making it happen.
Add a directory without code
Now that we’re on the same page, so to speak. This quick DigWP tutorial explains how to add an external directory to the auto-generated WordPress sitemap. And by “external”, I’m referring to any directory that is not under the purview of WordPress (based on its URL). More specifically, any directory or folder that you add manually to your site’s files.
Step 1: Requirements
Okay let’s dig into it. For this non-code trick to work, the main requirement is that your site has permalinks enabled (via the WordPress General settings ▸ Permalinks). So instead of query-string-based URLs:
https://example.com/?p=123
..your site’s rocking keyword-rich “pretty” URLs:
https://example.com/ai-will-replace-the-internet/
Other than permalinks, there are two other caveats:
- Directory name consists of alphanumeric, underscores, and hyphens
- Directory location is within the site’s root directory
These requirements are explained further as we continue with the tutorial..
Step 2: Add a directory
Next add a directory to your WordPress site. Anywhere in the root directory of your site. For example, when I moved my shapeSpace WordPress theme from its own domain to Perishable Press, I added a directory named /shapespace/ to the site’s root directory. So the resulting directory path is this:
https://perishablepress.com/shapespace/
Important: for this non-code technique to work, the folder name must consist of only alphanumeric characters, underscores, and/or hyphens.
Step 3: Add new Page
Next, visit the WordPress Admin Area and create a new page (via Pages ▸ Add Page). Make sure that the page has a URL/permalink slug that matches your directory path. So continuing with the /shapespace/ directory example, we would add a new page that is named shapespace, which results in a permalink URL that matches the external directory. So both the directory and the newly added page have the same URL:
https://perishablepress.com/shapespace/
That’s all there is to it. Once you publish the new page, WordPress will do its thing and automatically add the new URL to your XML sitemap.
Check it out..
As long as the external directory and WP Page have the same URL, your WordPress sitemap will include a link to your directory. And when you (or anyone, anything) follows the link, they will be taken to the directory, not the WordPress Page. To get a better idea of how it works, check out the pages sitemap at Perishable Press, and follow the link to the external /shapespace/ directory. Instead of pointing to the blank WP Page, the sitemap link points to the shapeSpace directory, which serves the shapeSpace homepage.
A few final notes
This “codeless” way of adding directories to the WP sitemap works seamlessly. The new URL appears in your site’s local search results and links to the external directory (not the blank WP Page). That means the contents of the WP Page never are displayed anywhere on the front end of your site. So you can add a note or whatever reminding your future self why this otherwise empty page exists ;)
And of course, the main benefit of adding a directory to your sitemap is so the search engines can find it, pick it up, and include it in the search results. And that’s just smart SEO.
What about adding files?
Does this tricksy non-code technique also work with external files (instead of directories)? Not really, because of the limitations in how permalinks are formatted. For example, permalinks end with a forward slash /, file names do not. Also special characters like periods/dots that are included in file names are not included in permalinks. So if you add an external file named external-file.html, the closest you can get with a static page name is /external-file-html/, which won’t work for the sitemap trick.
Fortunately you always can add files and directories and just about anything using the Sitemaps API now included in WordPress core :)



