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 🙂
I assume that the website has these pages.
|Display data from Items table.|
(1, 2, 3 are item_id.)
|<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 “https://example.com/sitemaps/index”
Let’s change this to “https://example.com/sitemap.xml”
Open /config/routes.php, then add this code around line 57.
Let’s access https://example.com/sitemap.xml.
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!