Split large xml sitemaps PHP script

Many people will be familiar with the popular Google (XML) Sitemaps Generator for WordPress I use it on all of my wordpress installs and have been very happy with it. Until about a month ago when I was installing it over at accommodationsphere.com and it created a sitemap for me nicely gzipped and weighing in at only 1-2mbs but a whopping 92,000 urls.

Does google accept sitemaps with that many files? Not unless they’re split across multiple sitemaps which contain less than 50,000 urls each and utilize a sitemap index file.

So I organized a nice little php script that I’ve got loaded in a cron job that runs to split that large sitemap.xml.gz file into smaller .xml.gz files and creates an index file.

It’s a little crude but I’m hoping to get this included as a feature in the above mentioned plugin rather than expanding on this little scripts abilities outright.

You’re free to use it, modify it and do what ever, but be nice; if you develop a bit of extra features or usability for it why not send me the code for inclusion in the next version.

Download PHP XML Sitemap Splitter Version 1.0

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
Tagged with:
 

5 Responses to “Split large xml sitemaps PHP script”

  1. D Maskull says:

    This is a great concept, and I have used it on one of my sites now – successfully. It would be great if this was made into an easier process though, like a plugin that automatically split the sitemap upon creation when a new post is made. Has anyone done this or expanded upon your original script?

  2. This is awesome, i was tiered of searching through forum about how exactly we can split the sitemap files in to different files, but i didnt get any valid solution. then i came here. now am going to install it.
    Thanks :)

  3. drinksforall says:

    I tried to run this script with my xml sitemap, but i got a memory error, is there any alternative to this?

  4. RayRay says:

    THANK YOU THANK YOU THANK YOU!!!!

    I have a Gallery 2 installation with a sitemap that is just insane and gets split into 4 parts. I was doing it by hand until I found your script. I made a bash script in my cronjob and added in hard paths to get it to work for my setup using:

    wget -q [url of my sitemap, it takes a while to download] -O – | gzip > [path]/sitemap.xml.gz

    Then I added a line for my Wordpress sitemap to be inputted as sitemap0.xml like I had previously. I actually learned a lot from your code, and I absolutely appreciate it.

  5. [...] I was able to automate my sitemaps thanks to a PHP script that I found. Google does not like it when there are more than 50,000 links in a sitemap, and my site has almost [...]




Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Simpler Computing - Wordpress Plugins - Help Desk Plugin