Camera WholesalerToys & Hobbies WholesaleErotic LingerieDesigner ClothingBondage Gears WholesaleLifestyle ChoicesShoes WholesaleWholesale Drop ShippingCrafting SkillsOnline TipsDrop ShippingBanner DesignHome & Garden ShopFree BlogsHealth and Beauty ShopComputers Wholesale ListDomain ParkingAntiques CollectionSouth Africa NewsletterWatchesMotorcycles Parts WholesalerBirthday Gift IdeasBird BathsNo RefererFirst Step MarketingNutritional DietLove SwingDoor Sex SwingGames Drop ShippingNew Concept AdvertisingFeng Shui

Posted Post

Posted People, Posted Life.

Wordpress Mu Google XML Sitemap Solution

After download the Google Sitemaps Generator, I thought it might easy to install on Wordpress mu system. But I am wrong, not that simple, I have to change lots of place to make it useful. Here is what I do and why:

First thing first, install:

Install the sitemap generator is same as install any other plugin, unzip and put it into plugin folder, like:

\wp-content\plugins\google-sitemap-generator

I am not put it into mu-plugins folder, because I do not want sitemap.xml for all blogs, I need give blogger choice, they can active it when they need sitemap. (Not everyone like sitemap IMO)

Now, Lets Make Some Change

function GetHomePath()

Find function GetHomePath at sitemap-core.php file, this function return the value of blog root, it works fine for single wordpress system, but for mu system, it will cause mess, as author recommend, we change this function, before return $res;

Global $blog_id;
if ($blog_id != 1) $res .= ‘wp-content/blogs.dir/’ . $blog_id . ‘/files/’;
return $res;

After change this function, the sitemap.xml and sitemap.xml.gz file will be placed at blog file folder.

Remove user ability to make key setting changes

WordPress mu is a multiuser system, you should not allow user to change some key sitemap setting, open sitemap-ui.php file,

Remove

} else if($k==”sm_b_location_mode”) {
$tmp=(string) $_POST[$k];
$tmp=strtolower($tmp);
if($tmp==”auto” || $tmp=”manual”) $this->sg->_options[$k]=$tmp;
else $this->sg->_options[$k]=”auto“;

This is for decide where the sitemap.xml placed, do not need for mu system

Remove

If($this->sg->GetOption(’sm_b_robots’)===true) {
if($this->sg->WriteRobotsFile()) {
$message.=str_replace(”%s”,$this->sg->GetRobotsFileUrl(),__(”<a href=\”%s\”>Robots.txt</a> file saved”,’sitemap‘)) . “<br />”;
} else {
$message.=__(”Error while saving Robots.txt file“,’sitemap‘) . “<br />”;
}
}

This is for how to change robots.txt file, as we know, for mu system, robots.txt file is generated on the fly, so cannot allow user to change it.

Remove

<li>

<input type=”checkbox” id=”sm_b_robots” name=”sm_b_robots” <?php echo ($this->sg->GetOption(”sm_b_robots”)==true?”checked=\”checked\”":”") ?> />
<?php echo str_replace(’%s’,(file_exists($this->sg->GetRobotsFilePath())?’<a href=”‘ . $this->sg->GetRobotsFileUrl() . ‘”>robots.txt</a>’:’robots.txt‘),__(”Modify or create %s file in blog root which contains the sitemap location.”,’sitemap‘)); ?>

<br />
<?php _e(”File permissions: “,’sitemap‘);
$f = $this->sg->GetRobotsFilePath();
$link = ‘ <a href=”‘ . $this->sg->GetRedirectLink(”sitemap-help-options-robots“,’sitemap‘) . ‘”>’ . __(”Learn more”,’sitemap‘) . ‘</a>’;
if(file_exists($f)) {
if(is_writable($f)) {
_e(”OK, robots.txt is writable.”,’sitemap‘);
} else {
echo __(”Error, robots.txt is not writable.”,’sitemap‘) . $link;
}
} else {
if(is_writable(dirname($f))) {
_e(”OK, robots.txt doesn’t exist but the directory is writable.”,’sitemap‘);
} else {
echo __(”Error, robots.txt doesn’t exist and the directory is not writable“,’sitemap‘) . $link;
}
}
?>
</li>

This is the UI (User Interface) part of robots.txt file change, if you do not user change it, so don’t let them see it.

Remove

<!– Location Options –>
<div class=”dbx-b-ox-wrapper”>
<fieldset id=”sm_location” class=”dbx-box”>
<div class=”dbx-h-andle-wrapper”>
<h3 class=”dbx-handle”><?php _e(’Location of your sitemap file‘, ‘sitemap‘) ?></h3>
</div>
<div class=”dbx-c-ontent-wrapper”>
<div class=”dbx-content”>
<div>
<b><label for=”sm_location_useauto”><input type=”radio” id=”sm_location_useauto” name=”sm_b_location_mode” value=”auto” <?php echo ($this->sg->GetOption(”b_location_mode”)==”auto“?”checked=\”checked\”":”") ?> /> <?php _e(’Automatic detection’,’sitemap‘) ?></label></b>
<ul>
<li>
<label for=”sm_b_filename”>
<?php _e(’Filename of the sitemap file‘, ‘sitemap‘) ?>
<input type=”text” id=”sm_b_filename” name=”sm_b_filename” value=”<?php echo $this->sg->GetOption(”b_filename”); ?>” />
</label><br />
<?php _e(’Detected Path’, ‘sitemap‘) ?>: <?php echo $this->sg->getXmlPath(true); ?><br /><?php _e(’Detected URL‘, ‘sitemap‘) ?>: <a href=”<?php echo $this->sg->getXmlUrl(true); ?>”><?php echo $this->sg->getXmlUrl(true); ?></a>
</li>
</ul>
</div>
<div>
<b><label for=”sm_location_usemanual”><input type=”radio” id=”sm_location_usemanual” name=”sm_b_location_mode” value=”manual” <?php echo ($this->sg->GetOption(”b_location_mode”)==”manual”?”checked=\”checked\”":”") ?> /> <?php _e(’Custom location‘,’sitemap‘) ?></label></b>
<ul>
<li>
<label for=”sm_b_filename_manual”>
<?php _e(’Absolute or relative path to the sitemap file, including name.’,’sitemap‘);
echo “<br />”;
_e(’Example’,’sitemap‘);
echo “: /var/www/htdocs/wordpress/sitemap.xml“; ?><br />
<input style=”width:70%” type=”text” id=”sm_b_filename_manual” name=”sm_b_filename_manual” value=”<?php echo (!$this->sg->GetOption(”b_filename_manual”)?$this->sg->getXmlPath():$this->sg->GetOption(”b_filename_manual”)); ?>” />
</label>
</li>
<li>
<label for=”sm_b_fileurl_manual”>
<?php _e(’Complete URL to the sitemap file, including name.’,’sitemap‘);
echo “<br />”;
_e(’Example’,’sitemap‘);
echo “: http://www.yourdomain.com/sitemap.xml“; ?><br />
<input style=”width:70%” type=”text” id=”sm_b_fileurl_manual” name=”sm_b_fileurl_manual” value=”<?php echo (!$this->sg->GetOption(”b_fileurl_manual”)?$this->sg->getXmlUrl():$this->sg->GetOption(”b_fileurl_manual”)); ?>” />
</label>
</li>
</ul>
</div>
</div>
</div>
</fieldset>
</div>

This part is for choose sitemap.xml location, same same, if you do not want user change it, better not allow them see it.

Change Default Settings

This is not must, but I recommend you change it, to make your user life easier

On sitemap-core.php file, you can find default value at function InitOptions

The change I made are:

$this->_options["sm_b_prio_provider"]=”GoogleSitemapGeneratorPrioByAverageProvider”;

The provider for automatic priority calculation, after I test, Google Sitemap Generator Prio By Average Provider is working better than Google Sitemap Generator Prio By Count Provider

$this->_options["sm_b_pingyahoo"]=true; //Auto ping YAHOO
$this->_options["sm_b_yahookey"]=’Q89D23fV34GSeqHjRl8o5i55ojmxrmwJPyMa_195mBnBaK6Vp_NB8y5WjnIoamjikw–’; //YAHOO Application Key, default for all

Default the sitemap not ping Yahoo after generated, because you need a yahoo key to ping it, so I put a key (get free form yahoo) as default, I suggest you get one free key from yahoo too and put there, of course if you like you may keep my key, not a big deal.

Done

Ok, it’s half done, all the change on the plugin is finished, if user active the plugin at them plugin page, a sitemap.xml and a sitemap.xml.gz (a zip verison) will be create and placed into the blog folder and ping the search engines.

Everything is perfect except: the sitemap.xml NOT at root folder, so when search engine spider come, it can claw nothing except a 404 error. The following is how to fix this:

Plug You Plugin in to mu-plugins

Don’t laugh, I know it’s a silly title, just some stupid thing have to do.

We know the php file in mu-plugins folder will be load automatically by WordPress. So I created a postedpost.php file and write all my little change and hacks inside, like my Ultimate WP Post Name URL Sanitize Solution, I suggest you do it to, very easy and convenience. Anyway, the following code should inside mu-plugins folder.

Put sitemap into Robots.txt file

Function postedpost_do_robots() {
global $current_blog;
if ( ‘0′ != $current_blog->public ) {
$siteurl = get_settings(’siteurl‘);
if ( class_exists( ‘GoogleSitemapGeneratorLoader’ ) ) {
echoSitemap: ” . $siteurl . “/sitemap.xml\n”;
echoSitemap: ” . $siteurl . “/sitemap.xml.gz\n”;
}
}
}
add_action(’do_robots’, ‘postedpost_do_robots’, 20);

As the new sitemap protocol, you can put sitemap location into robots.txt file, so search engine can find your sitemap without you told them, e.g. Google Webmaster Tool.

Rewrite Rules

Function postedpost_rewrite_rules_array($rules){
$newrules = array();
$newrules['sitemap\.(xml|xml\.gz)$'] = ‘index.php?is_page_redirect=1&redirect_method=sitemap&redirect_url=$matches[1]‘;
return $newrules+$rules;
}
add_filter(’rewrite_rules_array’, ‘postedpost_rewrite_rules_array’);

Function postedpost_parse_query($query){
global $blog_id;;
$siteurl = get_settings(’siteurl‘);
$uri = parse_url($siteurl);
if(!empty($query->query_vars['is_page_redirect'])){
$redirect_method = $query->query_vars['redirect_method'];
if ( $redirect_method == ‘sitemap‘ ) {
$redirect_url = $siteurl . ‘/wp-content/blogs.dir/’ . $blog_id . ‘/files/sitemap.’ . $redirect_url;
} else {
$redirect_url = get_settings(’siteurl‘);
Header(’HTTP/1.1 301 Moved Permanently’);
Header(’Location: ‘ . get_settings(’siteurl‘));
exit();
}
Header(’HTTP/1.1 302 Moved Temporarily’);
Header(’Location: ‘ . $redirect_url);
exit();
}
}
add_action(’parse_query’, ‘postedpost_parse_query’);

Function postedpost_init() {
global $wp_rewrite;
// postedpost_flush_rewrite_rules
$wp_rewrite->flush_rules();
add_rewrite_tag(’%comment_id%’, ‘(([0-9]{1,})’);

}
add_action(’init’, ‘postedpost_init’);

These code all about rewrite rules, when search engine or visitor visit /sitemap.xml, it will be 302 redirect to /wp-content/blogs.dir/[blog_id]/files/sitemap.xml. Btw, in my own code, I have many other rewrite rules and process code in these functions, that also why I say put all hacks in one php file, for make easier on process common task and improve performance.

OK, Done

This time all done. Here is the list of all files I talked above, you may check it.

Are you seeking for wholesale category about Engineering Textbooks Products Wholesale, Google Android Netbook, Computer Books and Internet Books For Sale, Eken, WordPress In Depth Price, Buy Sams Teach Yourself WordPress, Laptop Touchscreens Supplier, Mac TV Receiver, Netbooks, Mini Notebooks and Ultraportables, Build Your Own Wicked Price, Drop Ship Computer Science Textbooks, Other Brand Cell Phones and Smartphones Manufacturer and Cheap General, wholesale drop shipping is the only place to check.

Possibly related posts: (automatically generated)
Wordpress Mu Google XML Sitemap Solution

8 Comments »

  bruce wrote @ October 13th, 2008 at 4:19 PM

Thanks for this.. Much appreciated..

Now I can get the Google SiteMap Generator working on my WPMU sites..

Thanks for your valuable information.

  John wrote @ November 3rd, 2008 at 10:39 PM

Thank you for taking the time to post this. Unfortunately I get the error:

Parse error: syntax error, unexpected ‘=’ in /home/wpmu/public_html/wp-content/plugins/sitemaphack.php

on line:

$newrules['sitemap\.(xml|xml\.gz)$'] = ‘index.php?is_page_redirect=1&redirect_method=sitemap&redirect_url=$matches[1]‘;

Any help would be appreciated

  arsenie wrote @ November 7th, 2008 at 8:02 PM

thanks for your effort, looks like its working well with wpmu!

  Ivan | Irish Blogger wrote @ November 8th, 2008 at 7:57 PM

Isn’t it a bit too hard to read in so narrow column? Or am I geting old? :)

BTW I am in war with this MU sitemap thing… :)

Ivan

  Freaking Wildchild wrote @ March 10th, 2009 at 5:54 PM

I’ve sure developed some claustrophobia together with finding a seo friendly/sitemap solution for wordpress mu ;)

Incredible no-one has ported it yet to wordpress mu and release it through the addons; because sitemaps are the basic to get your site x-rayed inside out …

  ketemexudge wrote @ May 20th, 2009 at 11:45 AM

Super writing,, will visit again.

  Warren.rior wrote @ June 22nd, 2009 at 2:08 AM

This line looks fine. Remember it’s (’) a single quotation marks, not (`)

  nonbreakingspace wrote @ September 29th, 2009 at 12:40 AM

I’m having some trouble getting this approach to work with WP MU 2.8.4

It won’t let me access the generated sitemaps.

Your comment

HTML-Tags:
<a href="" title=""> <abbr title=""> <img alt="" align="" border="" height="" hspace="" longdesc="" vspace="" src="" width=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>