Add Wordpress html sitemap without plugin

Would you like to add sitemap to your Wordpress, here is the simple way to create sitemap without plugin.

Let's start it!

1. Create a new php file in your current activated theme folder and save it as sitemap.php

2. Paste the below code in it

Template Name: Sitemap
<?php get_header(); ?>

<div id="content" >
  <div class="post">
    <div class="title">
      <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
        <?php the_title(); ?>
<!-- ----------------- Display Post with its relative category ----------------- -->
    <div class="entry siteMap">
      <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(); ?>

3. Go to your Admin, create page and name it as “Site Map”. Assign to this page “Sitemap” template

That's all, enjoy.

Official wiyono blog