Software, Technology

How-to: WordPress Sitemap Page Without Plugins

Geographica restituta per globi trientes - Norman B. Leventhal Map Center at the BPL via Wikimedia CommonsHaving inherited development of a client’s site, I looked at the amount of clutter my illustrious predecessor had built up and decided it was time for a spring clean. It ddin’t help that some of the old plugins proved incompatible by the time we upgraded WordPress through six or seven versions.

I’ve come across recommendations for WordPress sites to function with a maximum of 10 plugins, for reasons of speed, flexibility, security and compatibility. Since we already had a site that was slow-loading, throwing errors and bulked up with plugins I hadn’t a clue how to work, it seemed like a good idea.

Then I realised the site needed a site map…

Could I create a simple WordPress Sitemap Page without using plugins to includes Pages, Posts and Custom Post Types? Yes.

Could I create one that actually worked with the theme I’m using? On my second attempt, yes.

Needless to say you need to have administrative access to your WordPress site and FTP access.

1:In your active theme folder, create a file named sitemap.php.

2: Paste the following code in to the sitemap.php file.
Template Name: Sitemap
<?php get_header(); ?>

<div id="content" style="float:left;">
<div class="post">
<h1 style="font-size:x-large; font-weight:bold;">Sitemap</h1>
<div class="entry siteMap">&nbsp;

<h2 id="posts">Posts</h2>
// Add categories seprated with comma (,) you'd like to hide to display on sitemap
$cats = get_categories('exclude=');
foreach ($cats as $cat) {
echo "<li><h3>".$cat->cat_name."</h3>";
echo "<ul>";
while(have_posts()) {
$category = get_the_category();
// Only display a post link once, even if it's in multiple categories
if ($category[0]->cat_ID == $cat->cat_ID) {
echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
echo "</ul>";
echo "</li>";
<!-- ----------------- Display Categories ----------------- -->
<?php wp_list_cats("sort_column=name&feed_image=/wp-content/themes/Horcrux/images/rss-small.png&optioncount=1&hierarchical=0"); ?>
<!-- ----------------- Display Pages ----------------- -->
<h2 id="pages">Pages</h2>
// Add pages seprated with comma[,] that you'd like to hide to display on sitemap
'exclude' => '',
'title_li' => '',
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Note that for this sitemap template to render properly with my theme, I have to float the main content <div> (else my sidebar drops below the foot of the sitemap) and do a bit of styling of my main heading text.

6. Create a new page in the backend of your WordPress install. Select the page template – HTML Sitemap.

This bit of PHP code scans your WordPress database and pulls in all the post,s categories and pages you have published on your site. You may need to have another spring-clean to tidy up and organise all those elements into a coherent page for your site visitors. RC

Related: How-to: Understand WordPress’ Goshdarnit

​​​​​Image credit: Geographica restituta per globi trientes – Norman B. Leventhal Map Center at the BPL via Wikimedia Commons.

About Robin Catling

Robin Catling gained degrees in both arts and technology which led to a diverse portfolio of employment. A freelance systems analyst, project manager and business change manager for the likes of American Express, British Airways and IBM, he moved on to web design, journalism and technical authoring. He has also worked in film and television, both behind and in front of the camera, including productions by Steven Spielberg, Martin Scorcese, Ron Howard and Ridley Scott. A qualified three-weapon coach, he runs West Devon Swords teaching sports fencing to all age groups, and in recent years qualified with the British Federation of Historical Swordplay to teach medieval and renaissance combat in the Historical Western Martial Arts.


One thought on “How-to: WordPress Sitemap Page Without Plugins

  1. Im using Google sitemap generator 4.0.7 on, search this plugin on and install with easy steps all settings are default. i strongly recommend this wp plugin.

    Posted by Bright Verge | Oct 11, 2014, 8:00 pm

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Twitter Updates

Follow us on Twitter @EverythingExpre

Find Us on Facebook

Enter your email address to follow this blog and receive notifications of new posts by email.



BBC World News

BBC World News
Opens the BBC World News page.
%d bloggers like this: