Sitemap is showing hidden pages

My sitemap is showing hidden folders. I am currently using this xmlsitemap.php:


$ignore = array('sitemap', 'error');

// send the right header
header('Content-type: text/xml; charset="utf-8"');

// echo the doctype
echo '<?xml version="1.0" encoding="utf-8"?>';

<urlset xmlns="">
	<?php foreach($pages->visible()->index() as $p): ?>
		<?php if(in_array($p->uri(), $ignore)) continue ?>
			<loc><?php echo html($p->url()) ?></loc>
			<lastmod><?php echo $p->modified('c') ?></lastmod>
			<priority><?php echo ($p->isHomePage()) ? 1 : number_format(0.5/$p->depth(), 1) ?></priority>
	<?php endforeach ?>

What am I doing wrong? When I load http://localhost:8888/mypage/sitemap still shows me hidden pages:

1 Like

If you want to show only visible pages, no matter on what level:

  foreach($pages->index()->visible() as $p) {
    //do stuff

Worked great! Thank you!