How to use XML Sitemap plug-in with WordPress MU

A couple months ago, I wrote a blog post in my Chinese blog about my own experience of configuring XML SiteMap plugin in the WordPress MU. It turned out that a lot of MU owners had the same problem before. So I decided to re-write it in English and share with you here.

I guess you should be familiar what the Google SiteMap is if you would like to increase your website/blog’s rank in search result. And you are using WordPress as your blogging platform, you might be interested in a plug-in called Google (XML) Sitemaps Generator for WordPress, which can allow you to easily generate Google XML SiteMap within your blog. But unfortunately the XML Sitemaps Generator (version 3.0.3) I used was not developed for WordPress MU. By default, it could only generate the XML sitemap for the primary blog not all other blogs in your WordPress MU.

Well, you can try your lucks on the author’s website to see whether he/she released a newer version to resolve the issue, or you can do it yourself by changing a few lines of code as I shared below.

In total, you can make the XML SiteMaps plug-in work in your WodPress MU with the following 3 steps.

First of all, you need change PHP code in the plug-in files. After you download Google (XML) Sitemaps Generator for WordPress (version 3.0.3) and unzip, you will get a folder named “google-sitemap-generator”. You need only to pay attentions on these two files, one is sitemap.php and the other is sitempa.xsl. For others, I do not think you really need them.

  1. OK, now open sitemap.php file in any text editor, and look up the function of GetBackLink().
  2. Comment out the last line of return $_SERVER[‘PHP_SELF’] . “?page=” . $page; 
  3. Insert two lines code: $path = get_option(‘siteurl’) . $_SERVER[‘PHP_SELF’] . “?page=” . $page; and return $path; Your final function code should look like the below:

function GetBackLink()
{
$page = basename(__FILE__);
if(isset($_GET[‘page’]) && !empty($_GET[‘page’])) {
$page = preg_replace(‘[^a-zA-Z0-9\.\_\-]’,”,$_GET[‘page’]);
}
//return $_SERVER[‘PHP_SELF’] . “?page=” . $page; $path = get_option(‘siteurl’) . $_SERVER[‘PHP_SELF’] . “?page=” . $page;
return $path;
}

Secondly, upload plug-in files to the directory of mu-plugins. Save your modified sitemap.php file, and upload this plug-in to your web server. You can upload to the plugins directory, but I prefer the /wp-content/mu-plugins directory to reduce individually activations. And again, I only upload two files (sitemap.php and sitemap.xsl) since I do not think I will need other un-necessary files.

Please be noted: you should upload these two files to the root of mu-plugins directory, not the google-sitemap-generator folder.

Finally, you need to customize the XML Sitemap plug-in for each blog.

Now, you can log onto your WordPress MU, and then Options. You will find a new XML-Sitemap option. Click it to customize configurations for each blog. Most of these options are same as these in regular WordPress, but you need to make the following three changes to allow XML-SiteMap work for all of your blogs in the WordPress MU.

  1. In Advanced Options, locate the “Include a XSLT stylesheet: Use Default (Full or relative URL to your .xsl file)” section and enter the correct location of your sitemap.xsl file. For example,  http://youdomain.com/wp-content/mu-plugins/sitemap.xsl if you upload that file to your mu-plugins directory as I suggested above. This option should be the same for all your blogs.
  2. In Location of your sitemap file, select the second option of Custom Location. And you should name your sitemap with different names in different blogs. For instance, my sitemap file for my second blog of http://lichao.net/weblog is sitemap_weblog.xml not the default sitemap.xlm. So its complete URL should be http://lichao.net/sitemap_weblog.xml. Remember, please use your blog sub-directory or sub-domain name here since the sitemap XML file needs to be physically located.
  3. Finally, just save your configuration, and build or re-build your sitemap files for all blogs. And you are done now!

6 thoughts on “How to use XML Sitemap plug-in with WordPress MU

Leave a Reply

Your email address will not be published. Required fields are marked *

Please Answer: * Time limit is exhausted. Please reload the CAPTCHA.