Jack Barber Design & Technology

01947 878108 info@jackbarber.co.uk

Create a Simple Sitemap Using Perch CMS

Create a Simple Sitemap Using Perch CMS

I've been using Perch for over a year now on all kinds of client and personal sites, and it is amazing!

Recently I've been looking at improving the performance of sites built with Perch - both from a speed perspective and also in terms of SEO (Search Engine Optimisation).

Here's how I go about creating a simple sitemap for a site built using Perch:

Create a New Navigation Template

Within the Perch navigation templates folder I create a new file called sitemap.html:


This file contains the following code:

<perch:before><?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <loc>https://YOURDOMAIN.co.uk<perch:pages id="pagePath" /></loc>

Don't forget to update YOURDOMAIN with your actual domain name!

Create a Sitemap Page

The second step is to create a new file in the root directory of your website, I call mine sitemap.php. It should contain this:

    header('Content-type: application/xml');

You could do this as a new Perch page - but that's unnecessary - it's simpler to just create an independent new .php file.

This file (sitemap.php) calls the Perch runtime and then spits out the list of pages which make up your site - you can then submit your sitemap to Google via Webmaster Tools, or reference it in your robots.txt file like this:

User-agent: *
Allow: /
Sitemap: https://YOURDOMAIN.co.uk/sitemap.php

Again - don't forget to enter your proper domain name.


This is pretty basic - but Google seems happy enough with it. As always, this is more a reference for my benefit that anyone elses, but if it helps you out feel free to make use of the code!