CakePHP3 – How to Create a Sitemap Without a Plugin




In this post, I’m going to share how to create a sitemap without a plugin.

I found cakephp3-sitemap plugin, but the installation by composer doesn’t work. (You can download manually, though.)

I’m not a big fan of using plugins, and also my project doesn’t have many Controllers and Views. So, I did it by myself.

The steps are exactly the same as when you create pages with CakePHP.
Create Layout, Controller, and View. That’s it!

I also confirmed that being able to submit a sitemap to Google Search Console.

Hope this helps 🙂


CakePHP 3.6.10
PHP 7.1.19


Sample Data

I assume that the website has these pages.

Top Page
Information Page
Contact Page
Display data from Items table.
(1, 2, 3 are item_id.)



Create /src/Controller/SitemapsController.php



Create /src/Template/Layout/sitemap.ctp



Create /src/Template/Sitemaps/index.ctp


About Tags

<loc> Required The page url.
<changefreq> Optional Update Frequency. Example: always, daily, yearly
<priority> Optional Valid values are from 0.0 to 1.0.

For more details, please check here.


Now, the url of this sitemap is “”
Let’s change this to “”

Open /config/routes.php, then add this code around line 57.


Let’s access
Were you able to generate the sitemap?


Finally, let’s submit the sitemap to Google Search Console.

Step1: Log in to Search Console and select your site.

Step2: Click “Sitemaps”

Step3 : Click the red “ADD/TEST SITEMAP” button.

Step4 : Type “sitemap.xml”, then click “Test” button.


If there’s no problem with the test, type “sitemap.xml” again, then click “Submit” button.
It’s all done!

Working as a freelance programmer in Japan. I try to make coding as simple as possible. Hope you enjoy coding 🙂