Magazine High tech

Google XML Sitemaps et WordPress Multisite

Publié le 11 novembre 2010 par Capmarketer

WordPress 3.0′s Multisite feature is cool and useful. The Google (XML) Sitemaps Generator plugin is also cool and useful. Unfortunately Arne Brachhold’s excellent plugin does not work with multisite blogs.

If you activate the plugin on a multisite enabled WordPress install, you get this error message.

Google XML Sitemaps et WordPress Multisite

Which is a shame, but it did not take me a long time to find a work around. My setup is using multisite with sub-domains and with the Domain Mapping plugin. These instructions are for the 3.2.4 version of the plugin.

1. Modify the plugin

Edit the file wp-content/plugins/google-sitemap-generator/sitemap.php and comment out lines 53 to 58 to look like this

1
2
3
4
5
6
7
8
//Check for 3.0 multisite, NOT supported yet!
// if((defined('WP_ALLOW_MULTISITE') & WP_ALLOW_MULTISITE) || (function_exists('is_multisite') & is_multisite())) {
//      if(function_exists('is_super_admin') & is_super_admin()) {
//              add_action('admin_notices',  array('GoogleSitemapGeneratorLoader', 'AddMultisiteWarning'));
//      }
//
//      return;
// }

You can delete these lines, but I prefer to comment them out. All this does is prevent the plugin from detecting the multisite setup and not becoming active.

2. Get your rewrite rules ready

In your blog’s .htaccess file add these lines above your WordPress rules

1
2
RewriteRule ^sitemap.xml sitemap-%{SERVER_NAME}.xml [L]
RewriteRule ^sitemap.xml.gz sitemap-%{SERVER_NAME}.xml.gz [L]

This will come in handy later.

3. Activate the plugin and set these options

Now on each of your sites in your WordPress network, activate the Google (XML) Sitemap plugin. Do not Network Activate it.

Now got to your XML-Sitemap options page and for “Location of your sitemap file” select Custom location.

Google XML Sitemaps et WordPress Multisite

In the custom location change your change the file name sitemap.xml to sitemap-yourblogservername.xml. My server name is blog.dembowski.net so I’m using sitemap-blog.dembowski.net.xml. Save the options.

Look in your WordPress installation’s root and check if you have sitemap.xml or sitemap.xml.gz. If you do then delete them both.

Now at the top of that options page, click on “rebuild the sitemap manually” and confirm that your new sitemap-yourblogservername.xml has been created.

4. Test and confirm that this worked

Now test two things. Start by pointing your browser to http://yourblogservername/sitemap.xml and then http://yourblogservername/sitemap-yourblogservername.xml. If you setup your .htaccess rewrite rules correctly, then both URLs should work.

Load up your WordPress generated robots.txt file via http://yourblogservername/robots.txt and look at the Sitemap line. Mine reads like this

1
2
3
4
User-agent: *
Disallow:
 
Sitemap: http://blog.dembowski.net/sitemap-blog.dembowski.net.xml.gz

I have that rewrite rule in case the default location for the sitemap is used.  When you load the sitemap via the normal location, the rewite rule sends it to the correct location. The second gziped sitemap URL is fine.

There should be no real sitemap.xml or sitemap.xml.gz files in your blog’s root directory. Instead, each sitemap file should have your virtual WordPress network names instead.

5. Rinse and repeat

Repeat this process for each site in your WordPress Network and you can continue to use this sitemap plugin. You will need to activate the plugin in each of your sites and change sitemap.xml to include the site name just as I outline in step 3.

6. The caveat

If this works for you, great! But if it doesn’t, please don’t bug Arne. If and when he makes his plugin multisite compatible, then it will be probably a better solution than this one. I’m not seeing any PHP errors or warning in my log files, but there may be reasons why this is not a good idea.

Also, when you modify your copy of a plugin in the WordPress plugin repository and that plugin is updated you will lose your edits from step 1 when you update the plugin.

In the meanwhile, I can continue to use this excellent plugin.

Source: blog.dembowski.net.

Articles similaires


Retour à La Une de Logo Paperblog

A propos de l’auteur


Capmarketer 288 partages Voir son profil
Voir son blog

l'auteur n'a pas encore renseigné son compte l'auteur n'a pas encore renseigné son compte

Magazine