Skip to content

How to Add Automated Sitemap Functionality

  • by
  • SEO

If you want to index your website accurately by the priority, importance of page and structure, a sitemap.xml file is highly recommended to do it efficiently. Here we are just going through a detailed article to make a quality sitemap by a PHP script which can automatically generate your website’s sitemap. Every time you update your website or publish a new article, the sitemap.XML file also updated with the URL of the news article.

There are many plugins to do this, but I believe in simplicity and prefer to create a theme functionality that can help to generate a sitemap without any plugin. You can also find many scripts to do this stuff. However, your method is handy other than the sitemap generated by plugins. (I do not like them because they put URL’s of their website before or at the end of sitemap). So I just want to create a sitemap as Google does it.

After researching, I found some methods to build an automated sitemap.XML file in the root directory from theme function.php. Here I am just going to share the best of them which is nice to work with my theme.

Step-1: Open your function.php file and add the following script before the closing tag. Find the scripts below. Download it from here:

This script generates a sitemap on your website’s page and posts. If you want to include any other post type with this sitemap simply include it at the “post_type ” line:

'post_type'   => array( 'post', 'page' , 'Bangla'),

If you want to create a sitemap for video or attachment or news, you can modify these scripts in the following direction. For details, just see the normal .xml structure provided by google. Read more about How to make Sitemap for Search Engines for detailed instruction and understanding.

If you want to make a list of the sitemap.xml file, then just try to include different types of a sitemap by tweaking this code. Then you can make a final index_sitemap file by calling them all in your functions.php file. It is possible but just needs your attention to generate a good working auto-generated PHP script for the sitemap index file. Think about it and make it accurate! This option is open to you! No more today! Have a fabulous and great day!