Sitemaps are useful to tell search engines about different pages of your website. Once you submit a sitemap to a search engine, they can crawl all the links which you provided in your sitemap. So generating a sitemap for your website is very important. If you don’t have a sitemap for your site, create one by Google Codes or manually create one by Learning how to create a sitemap (it’s nothing but a simple XML file!)

Now, there are two ways for making a scheduled update for your sitemap:

Automatic: By PHP & Cron Job

Download this PHP file. Give it a name, like “sitemap_updater.php”. Edit it to type in it the correct location of your sitemap. Now upload it to your server, suppose in /public_html/cron_jobs/ directory. Give the file a name, for example, sitemap_updater.php

Now, go to Cron job section of your server from the Control Panel/Admin account of your hosting. If you’ve acces to Cpanel, you may click cron jobs like following:

Next, click a option that suits you most. If you’re new, click standard

Cron job - how to select method
Cron job – how to select method

Next we’re on the main panel. Select your schedule – how often you want to run the code. Then in the command to run box, type the following command:

php -f /home/your-username/public_html/cron_jobs/sitemap_updater.php

Look at the URL: /home/your-username/public_html/ replace it with appropritae location of your root directory.

If you have a different location for the sitemap_updater.php file, type it accordingly. The following screen-shot might be helpful (ignore the command given in the image)!

Cpanel how to execute PHP file as a Cron job

More details on Cron jobs here

Download the Sitemap_Updater.php file


Manually Updating Site-maps

Well, if you don’t have access to PHP/Cron jobs, you can manually update sitemaps. The trick is, we will create a HTML file, save it in our local disk, and run the file manually whenever we need to update the sitemap!

  1. Download this HTML file
  2. Rename it like something.html
  3. Open the file for editing, edit line # 5, give here your sitemap address. Save it
  4. Now whenever you need to update your sitemap, just open the HTML file in your brower! šŸ™‚

Well, that’s all. Rock with your sitemaps šŸ˜€

17 thoughts on “PHP Auto Sitemap Submit Script for Google Bing Yahoo or Other Search Engines

      1. The image shown here gives instruction on how to run cron every 5 minutes. You can set an interval that suits your site best šŸ™‚

  1. How do i know if its executed successfully? Do i have to submit my website to google webmaster in order to do this?

    1. In the php script you may send a mail to yourself, including the time the script ran. You may submit to google webmaster (recommended) – it’s extremely helpful.

      1. Oh so can i take it that i have to manually submit once to google webmaster and let this script + cron job auto-submit the sitemap afterwards?

  2. i want my site to update the xml feed, this script i believe is just for ping the xml feed what is the point if the xml feed sitemap hasn’t been updates. do you have a script and cron for updating the sitemap?

Comments are closed.