How to Create HTML Sitemap in WordPress Without a Plugin

The sitemap contains the list of pages (i.e, category page, blog page, etc) on the website which is accessible to the users. Click here to navigate our website sitemap page for your reference. You can find lots of HTML sitemap plugins for WordPress. But in this blog, I will show you how to create HTML sitemap dynamically in WordPress without using any plugin. Dynamically means that the sitemap updates automatically with every new post and other blog changes.

Here are the steps to create HTML sitemap in WordPress dynamic,

Step 1:

Create a PHP file named page-sitemap.php in your WordPress theme folder.

Sample file path: <WordPress Installed Root Folder>/wp-content/themes/<Your Theme>/page-sitemap.php

Step 2:

Add the following code in the newly created file (page-sitemap.php),

 * Template Name: HTML Sitemap Page
 * Create Dynamic HTML Sitemap in WordPress


    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

            <div class="html-sitemap">
                <ul class="sitemap-authors">
                    <?php wp_list_authors('exclude_admin=1&optioncount=1'); ?>
                <ul class="sitemap-pages">
                    <?php wp_list_pages(array('exclude' => '', 'title_li' => '')); // Exclude pages by ID ?>

                        $categories = get_categories('exclude='); // Exclude categories by ID
                        foreach ($categories as $cat) {
                            <li class="category">
                                <h3><span class="grey">Category: </span><?php echo $cat->cat_name; ?></h3>
                                <ul class="cat-posts">
                                    query_posts('posts_per_page=-1&cat='.$cat->cat_ID); //-1 shows all posts per category. 1 to show most recent post.
                                        $category = get_the_category();
                                        if ($category[0]->cat_ID == $cat->cat_ID) { ?>
                                                <?php the_time('M d, Y')?> &raquo; <a href="<?php the_permalink() ?>"  title="<?php the_title(); ?>"><?php the_title(); ?></a> (<?php comments_number('0', '1', '%'); ?>)
                    <?php } ?>
                <?php  wp_reset_query(); ?>

                <ul class="sitemap-archives">
                    <?php wp_get_archives('type=monthly&show_post_count=true'); ?>



Step 3:

Then, login to your WordPress admin panel, and on the left sidebar, go to Pages > Add New.

This will create a new page as shown in the image below:

How to Create HTML Sitemap in WordPress Without a Plugin

Here, enter the page title like Sitemap, In the Page Attributes section, choose the HTML Sitemap Page template and then click Publish. Now the sitemap page will be created and you can check it in the frontend.

Hope this helps.

6 Comments on “How to Create HTML Sitemap in WordPress Without a Plugin”

    1. Thank you for the code as well. I was able to get this sitemap working on my website. I had to change the owner of the sitemap.php to match the owner of my WordPress files.

      Also, I had to change the group to match the group account for the WordPress files. I did not receive a 500 error. For example:

      chown user sitemap.php
      chgrp user sitemap.php


  1. Hi there, I’ve tested your code and it works. Thanks so much! But there are some issues. One small issue I have is how do I exclude particular pages or posts? For example, I would like to exclude the Login page.

    My second issue is that my blog sidebar is positioned all the way at the bottom of the page on the Sitemap page, is there a way I can remove the blog sidebar for this page? I would like to refrain from using display: none; if possible


  2. Thank you!

    Working fine!

    One more question! Is there a way to show that one page is a sub-page?

    I tried, but have no luck.

Leave a Reply

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