How to Create a WordPress Sitemap

A sitemap is a list of all the pages of a website, usually in a hierarchical fashion, accessible to search engine crawlers or website users. It can either be a document in any form that can be used for web design and development, or a web page containing the site’s page list.

Basically, there are two types of sitemaps – an XML file that you submit to search engines, visible to the crawler but not to your website visitors, and, as already mentioned above, a page on your website which contains a list and summary of all the pages. The latter, which will be discussed here, is visible and accessible to both the search engine crawler and your website visitors.

The importance of sitemap

Aside from providing visitors with convenient navigation, a sitemap on your website can also:

  • •   give the website visitor an idea of how big your site is
  • •   serve as an overview of the entire website
  • •   increase the “time on site” of your visitors as this navigation system will most likely make them click more than one of your website pages
  • •   provide crawlers a complete structure of your site which they can use to efficiently retrieve and index pages
  • •   serve as an excellent way to notify all search engines that you’re updating your site every time a new page or content is added

Adding a sitemap to your WordPress site

There are two ways on how to add a sitemap to your site:sitemap

  • •   By creating a sitemap.php template
  1. Access FTP and locate your WordPress theme folder. Make a copy of the page.php file and rename it as sitemap.php
  2. View and edit the new sitemap.php file using any text editor.
  3. On the sitemap.php file, locate this code <?php the_content(); ?>
  4. Replace it with the following code below:

<h3>Pages</h3>

           <ul><?php wp_list_pages(“title_li=” ); ?></ul>

                        <h3>Feeds</h3>

                                    <ul>

                                 <li><a title=”Your full content” href=”feed:<?php bloginfo(‘rss2_url’); ?>”>Your Main RSS</a></li>

<li><a title=”Comment Feed” href=”feed:<?php bloginfo(‘comments_rss2_url’); ?>”>Your Comment Feed</a></li>

                                  </ul>

                        <h3>Categories</h3>

                                  <ul><?php wp_list_cats(‘sort_column=name&optioncount=1&hierarchical=0&feed=RSS’); ?></ul>

                        <h3>All Blog Posts:</h3>

                                  <ul><?php $archive_query = new WP_Query(‘showposts=1000&cat=-8’);

                                                                              while ($archive_query->have_posts()) : $archive_query->the_post(); ?>

                                                                                                      <li>

<a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></a>

                                                                            (<?php comments_number(‘0’, ‘1’, ‘%’); ?>)

                                                                            </li>

                                                                              <?php endwhile; ?>

                                  </ul>

                        <h3>Archives</h3>

                            <ul>

                                <?php wp_get_archives(‘type=monthly&show_post_count=true’); ?>

                            </ul> 

  1. Add this code on top of your sitemap.php file:

<?php
/* Template Name: WordPress Sitemap */
?>

  1. Login to your WordPress and create a new page. Name it as “Sitemap”. In the “Page Attributes” section, set the “Template” option to “WordPress Sitemap”.
  2. Publish the page.
  • •   By editing the functions.php file 
  1. Access and open your functions.php file
  2. Add the code snippet below:

 <?php

 add_shortcode(‘sitemap’, ‘wp_sitemap_page’);

 function wp_sitemap_page(){

    return “<ul>”.wp_list_pages(‘title_li=&echo=0’).”</ul>”;

}?>

wp_list is a built-in WordPress function that you can utilize to quickly list and display all you website pages.

  1. Login to your WordPress and create a new page. Name it as “Sitemap”.
  2.  Add this shortcode in the page:

 [sitemap]

Image by Flickr

Article By: Wasim Ismail

Wasim’s a project manager at Alrayes Web Solutions along with an online SEO consultant & blogger for business at wasimismail.com, specialising in online business.


Comments are closed.