How to Create A WordPress Sitemap

Posted on February 19, 2014

When it comes to site navigation…simplicity is the name of the game.  But what do you do when you have a site that pushes the fifty page mark and you still want people to be able to find what they need?  Well you include search functionality of course but in addition  to that, a sitemap is a great way to display your site’s contents in one convenient location.  To get started, decide what you want to show on your sitemap page.  Generally speaking, you will want to include all of your pages and probably a list of your site’s blog categories, tags or most recent posts.  If you were working with a static HTML site this would be very difficult to produce.  But you’re not…you’re coding with the power of WordPress!  Here we go…

1.  If you are reading this article, your theme probably doesn’t have a sitemap page template so you will need to create one.  Don’t worry…it’s very simple.  Start by getting into your FTP directory and creating  a copy of the “page.php” file.  This is your default page template that is used for all pages unless something more specific is available.  Need to catch up on the rules of template heirarchy?  No worries…I’ll wait while you check out the Codex.

2.  Edit the contents of your newly created “page.php” copy.  While you’re at it you might as well rename the file to “page-sitemap.php” which will ensure that WP uses it to display the sitemap page as long as you called the page “Sitemap”.  If you want to call it something different, go for it, but be sure to use that page name in the template name replacing “sitemap”.  Moving on…in the contents of the file you will want to remove the loop that displays the posts.  It will look like this: <?php while ( have_posts() ) : the_post(); ?>.  Replace that code with the following:

For pages

<ul><?php wp_list_pages( ); ?></ul>

For Categories

<ul><?php wp_list_cats( ); ?></ul>

For Archives

<ul><?php wp_get_archives( ); ?></ul>

3.  You’re done!  Now you can choose to use some of the various arguments that can be included within the parentheses to fine tune your sitemap such as only including certain categories or excluding certain pages.  You can also style the output by including some CSS classes in the output.


Leave a Reply

Your email address will not be published. Required fields are marked *


Ready to Get Started? Call 203.516.0359