Exclude page from a wordpress sitemap

I came across a tutorial on the internet for creating a sitemap in WordPress. It does what I want – it lists all pages and posts on the website however I was wondering if it was possible to exclude a page from the sitemap. In this case I want to exclude the sitemap link. Is it possible to do this? I have included the code for the sitemap below.

<?php
/*
Template Name: Sitemap
*/

get_header(); ?>


<?php if ( have_posts() ) : while( have_posts() ) : the_post();
    the_content();
endwhile; endif; ?>

<h2>Pages</h2>
<ul>
<?php
// Add pages seprated with comma[,] that you'd like to hide to display on sitemap
wp_list_pages(
  array(
    'exclude' => '',
    'title_li' => '',
  )
);
?>
</ul>

<h2>Posts</h2>
<?php
// Add categories seprated with comma (,) you'd like to hide to display on sitemap
$cats = get_categories('exclude=');
foreach ($cats as $cat) {
  echo "<ul>";
  query_posts('posts_per_page=-1&cat='.$cat->cat_ID);
  while(have_posts()) {
    the_post();
    $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>";
}
?>

<?php get_footer(); ?>

I am aware that the comments within the code give me some idea as to where to list the pages I want to hide however I am unsure as to how to do this. If anyone can help me it would be much appreciated.

Read More

Many Thanks.

Related posts

1 comment

  1. If you want to exclude pages from your Site Map you have to write here

       wp_list_pages(
          array(
            'exclude' => 'ID1, ID2',
            'title_li' => '',
          )
        );
    

    ID1 and ID2 it’s your page id on WordPress.

Comments are closed.