Generate a sitemap or sitemap index file for your web application with the CodeIgniter PHP framework.
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
application Controller and Model Oct 31, 2015 Add installation instructions Nov 1, 2015

CodeIgniter Sitemap Generator Model

Generate a sitemap or sitemap index file for your web application with the CodeIgniter PHP framework. This CodeIgniter model quickly enables you to generate a valid SEO-friendly sitemap file for you web application and/or website. An XML sitemap file helps crawlers of search engines to easily navigate and browse through your website and understand the structure of the different urls.

What are sitemaps?

Sitemaps are an easy way for webmasters to inform search engines about pages on their sites that are available for crawling. In its simplest form, a Sitemap is an XML file that lists URLs for a site along with additional metadata about each URL (when it was last updated, how often it usually changes, and how important it is, relative to other URLs in the site) so that search engines can more intelligently crawl the site.

Web crawlers usually discover pages from links within the site and from other sites. Sitemaps supplement this data to allow crawlers that support Sitemaps to pick up all URLs in the Sitemap and learn about those URLs using the associated metadata. Using the Sitemap protocol does not guarantee that web pages are included in search engines, but provides hints for web crawlers to do a better job of crawling your site.

Read more about the Sitemap protocol on


Copy the files in the application folder into your CodeIgniter application folder. This includes the model file and an example controller file. Follow the instructions below on how to use the model in your own controller.


The model is designed to be called and controlled by a CodeIgniter controller. The model does not create and save an actual XML-file to be saved on the disk. Rather, it generates a valid XML-file upon each request and directly serves it to the controller and thus the client browser.

This means that two examples of sitemap files to submit to search engines could look like the following urls:

Load the model

You can load the sitemap model from your CodeIgniter controller with the following line of code:

Add an item

To add an item to the sitemap, use the following line of code:
$this->sitemapmodel->add('', '2015-11-02', 'monthly', 0.9);

This function checks for the validity of the item on two points:

  1. The value of the parameter changefreq must be one of the following options:
    • always
    • hourly
    • daily
    • weekly
    • monthly
    • yearly
    • never
  2. The value of the parameter priority must be a value between 0 and 1

If any of the checks fail, an error is triggered by the model.

Generate a sitemap file

When you have inserted all the items in the sitemap, you can call the SEO-friendly valid XML-code by calling a simple line of code:

Generate a sitemap index file

A sitemap index file is a sitemap pointing to one or more other sitemap files. This helps search engine crawlers to easily understand the diversity of sitemaps that are served by your website. To call a sitemap index file instead of a regular sitemap file, simply add the string 'sitemapindex' as a parameter to the output-function, like this:

Clear the sitemap

If you wish to clear the items in the sitemap, call the following function: