I was looking into getting Google Sitemaps running today, and didn’t find much in the way of WordPress-MU compatible sitemap plugins. The only article I found was on a website that wasn’t responding, and looking at its Google Cache, it was a bit dated.
All of the plugins I could find seem to put the sitmap.xml file in the WordPress install directory. The problem with that is that the directory isn’t apache writeable, which means you have to touch and change the permissions of the files manually. Also with WordPress-MU, there may be more than one blog in use for that installation, so you can’t serve these multiple blogs’ sitemaps from a single location.
I took a few of the cached article’s ideas and made them easier to do. This guide will work on WordPress-MU 2.7 (the latest release).
First install the Google XML Sitemaps Generator plugin.
Open up the sitemap-core.php file in the plugin’s folder, and make the following changes:
In the function “GetXmlUrl”, line 1351, change to:
1351 1352 1353 1354 1355 1356 1357 1358 | function GetXmlUrl($forceAuto=false) { if(!$forceAuto && $this->GetOption("b_location_mode")=="manual") { return $this->GetOption("b_fileurl_manual"); } else { return trailingslashit(get_bloginfo('siteurl')) . 'files/' . $this->GetOption("b_filename"); } } |
and in the GetXmlPath function, line 1382, change to:
1382 1383 1384 1385 1386 1387 1388 1389 | function GetXmlPath($forceAuto=false) { if(!$forceAuto && $this->GetOption("b_location_mode")=="manual") { return $this->GetOption("b_filename_manual"); } else { wp_mkdir_p(ABSPATH . UPLOADS); return ABSPATH . UPLOADS . $this->GetOption("b_filename"); } } |
This will make the sitemap builder create the files in the current site’s uploads directory, and point the filename located in the virtual robots.txt file to the site’s files url. e.g. http://www.webtatic.com/blog/files/sitemap.xml
This will mean that the sitemap files will be stored on a per blog basis, inside the blog’s uploads folder, which is set to apache writeable on the initial WordPress installation.
That’s all there is to it. You can now rebuild the sitemap, or let it rebuild automatically when you submit new posts.
A simple and elegant solution
Maybe you should suggest it as a configurable option to the plugin maintainer….
Hi, very good solution. But before setup i want to know will this plugin makes individual sitemaps for all blogs under wpmu?
I use subdomain option. I don`t want that frontpages or other subblogs pages, articles would be apperared in other blogs sitemap.
Please reply,
Thank you.
Hi,
Yes, this plugin, with my changes, will make individual sitemaps. It stores them in the wp-content/blogs.dir/[id]/, which already has the .htaccess RewriteRule that’s needed to allow different sitemaps per host.
It will also automatically add to your robots.txt the location of your sitemap, e.g.:
Sitemap: http://www.webtatic.com/files/sitemap.xml.gz
Sitemap readers will check for this, so you wont need to put in any redirects to /sitemap.xml
If your blogs don’t sit at the root path of the domain or subdomain, you will have to add your own robots.txt in the root path to point to the correct location.
Hi,
I have got error with the new version of plugin. I have replaced:
function GetXmlUrl($forceAuto=false) {
if(!$forceAuto && $this->GetOption(“b_location_mode”)==”manual”) {
return $this->GetOption(“b_fileurl_manual”);
} else {
return trailingslashit(get_bloginfo(‘siteurl’)). $this->GetOption(“b_filename”);
}
}
With first custom code and:
function GetXmlPath($forceAuto=false) {
if(!$forceAuto && $this->GetOption(“b_location_mode”)==”manual”) {
return $this->GetOption(“b_filename_manual”);
} else {
return $this->GetHomePath() . $this->GetOption(“b_filename”);
}
}
With second custom code.
I have replaced the lines (also the required lines are changed) and got error:
” Parse error: syntax error, unexpected ‘;’ ”
on line:
” if(!$forceAuto && $this->GetOption(“b_location_mode”)==”manual”) { ”
I think the variables are changed in new version. Is there any solution?
Thank you.
It’s a parse error, so wont be caused by changed variable names. The error you say doesn’t appear to be on the line you say.
Could you try redownloading the plugin and trying again? Try only replacing the 2nd “return” line in each function, as that’s the only real change I made.
Won’t putting the sitemap.xml files not actually break the way sitemaps are supposed to work?
If you put a sitemap in the ‘files’ subdirectory, search engines will only work for URLs that lie within the ‘files’ directory.
http://www.arnebrachhold.de/2006/04/07/google-sitemaps-faq-sitemap-issues-errors-and-problems/#P28_whaturldenied
No, it shouldn’t be a problem. robots.txt could even point to a sitemaps on another host as long as the urls in it match the same domain as the host of the robots.txt.
From your link, it says there is a problem, but I’ve not gotten any errors on Google Webmaster Tools for it, its happy with all the links in it.
thanks a lot, works like a charm. woooot no more wpmu xml sitemaps headaches
Thanks very much, works great
Thanks a lot. You are realy a saviour.
Outstanding work. Keep it up.
Thank you for this guide. Works like a charm. This really was what we needed for our website. WordPress MU is pretty different in some cases from the regular WordPress. But well, now it works. Thanks again.