Code to use for your Sitemap
by Kyle Anderson
November 21, 2024

Depending on how your site is setup, here is an example snippet of code you can copy/paste to use for your sitemap in WordPress. This will list them out.
You can place the below on your 404.php as well.
<h2>Our Pages</h2>
<ul>
<?php wp_list_pages(‘sort_column=menu_order&title_li=&post_type=page&exclude=33,101’); ?>
</ul>
- This is sorted by the menu order of your website.
- Anything that is a “page”
- This for example is a “post” and not a “page”.
- “Exclude” is just removing pages you don’t wish to add. Those numbers are the page IDs.
Create a page called “Sitemap” and then copy/paste the code to page.php.
if(get_the_ID() == 1102) // sitemap page ID
{
?>
<h2>Our Pages</h2>
<ul>
<?php wp_list_pages(‘sort_column=menu_order&title_li=&post_type=page&exclude=33,101’); ?>
</ul>
<?php
}
?>