Google Sitemaps on WordPress-MU
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:
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:
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.