In the Loupe

Statamic Sitemap in Sixty Seconds

Statamic Sitemap in Sixty Seconds Featured Image

Sitemaps are probably the last checkbox ticked before launching your new site. Thankfully with Statamic it takes less than a minute to complete this task.

Download the Statamic plugin called Plugin-Sitemap by Max Westen.

After downloading, place the “pi.sitemap.php” file in a folder called “sitemap” and drop it into your “_addons” folder. You won’t need the files in the content, layouts and content folders.

Create a layout file in your theme called “sitemap.html”. Drop this code in there:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{{ sitemap }}
<url>
  <loc>{{ loc }}</loc>
  <lastmod>{{ lastmod }}</lastmod>
  <changefreq>{{ changefreq }}</changefreq>
  <priority>{{ priority }}</priority>
</url>
{{ /sitemap }}
</urlset>

To tell Statamic what to do with your “sitemap” slug. In your _config > routes.yaml file add:

routes:
  /sitemap:
    layout: sitemap

Lastly, tell the search engines where to find your sitemap. In the root of your website, add a robots.txt file. My site’s robot.txt file looks like this:

# robotstxt.org/

User-agent: *

Sitemap: http://lou.pe/sitemap

Host: http://lou.pe

If you don’t want to wait for Google to find your robots.txt file, submit your sitemap to Google Webmaster Tools and Bing Webmaster Tools.