This post details how to setup regional targeting for a WooCommerce Multisite shop with each site targeting users in different geographical regions worldwide in search engine results.

Use Case – Different Regional Users, Same Language

The specific scenario we are discussing is one where we have duplicated the same website on two different network sites within a WordPress Multisite setup.  The goal of each site is to targeting a set of users in a different region of the world which happen to have the same language, but different product pricing, currency and inventory.  Our example is using a folder structure to host each site in its own folder e.g. “example.com” is the US site and “example.com/au/” is the Australian (AU) site.

Note, that in our example the language happens to be the same, however the rest of this article is valid for different languages as well.

SEO WooCommerce Multisite Considerations

If you are at all familiar with Search Engine Optimization (SEO), you will have heard of the term “duplicate content”.  Basically, it’s a big no no in SEO and you should avoid it like the plague.  So in the case aforementioned, we have generated a lot of duplicate content since the websites are clones of each, so how to deal with this conundrum?

My first instinct was to use a canonical tag with one network site linking to the other on each page to inform search engines that one page was basically a duplicate of the other.  This worked, sort of…it fixes the duplicate content issue, but it causes the website with the canonical tags not to show up on search engine results which is not our intention.

Enter the hreflang tag

The hreflang tag is the right solution for our situation.  Google has a detailed page on how to use the href tag on their support page and on it they specify when to use hreflang:

Your content has small regional variations with similar content in a single language. For example, you might have English-language content targeted to the US, GB, and Ireland.

What these tags basically tell search engines is that one network site within the website is targeting one region and another site is targeting another region and that each one should rank in the relevant regional search engine accordingly.  For example if we have a US website “example.com” and a Australian website “example.com/au/”, we would want the “example.com” pages to rank on “google.com” and for “example.com/au/” to rank on “google.com.au”.

Ideally, what we would want is to have unique content written for each site that is targeted to the different users in each region.  This is not always possible so try to modify at least the relevant parts of each site accordingly, for example when writing about shipping and handling.

Implementing hreflang in WooCommerce Multisite

As always, I tried to search for a plugin that can easily add the hreflang tags for a WooCommerce Multisite scenario and even though there is a plugin that allows you to manage hrefs, I found it quite tedious to enter the links for each page manually.

Quick note, if you are using WPML the plugin automatically adds the hreflang tag for each language you setup.

So instead of using the plugin, I coded a simple function that does all the work in a few lines:

add_action('wp_head','set_meta_country', 10);
function set_meta_country() {
 global $wp;
 $current_url = home_url(add_query_arg(array(),$wp->request));
$blog_id = get_current_blog_id();
 if($blog_id == 1) {
 $us_url = $current_url;
 $au_url = str_replace(".com", ".com/au", $us_url);
 } elseif($blog_id == 2) {
 $au_url = $current_url;
 $us_url = str_replace(".com/au", ".com", $au_url);
 }
?>
 <link rel="alternate" href="<?php echo $us_url; ?>" hreflang="en-us"/>
 <link rel="alternate" href="<?php echo $au_url; ?>" hreflang="en-au"/>
 <?php
}

What this function does is hook into the “wp_head” action that fires every time a page is loaded and then simply adds the correct hreflang tags for that page in the <header> section.

Note, I am assuming in this function that each page on one site has a similar page on the duplicated site with the same URL structure.  If one site does not have a page on the other site, you will see errors in Google Webmaster Tools:

 

How to use the code

If you want to use the code above there here are instructions on what you have to do:

  • You have to make sure which “$blog_id” corresponds to which website and hence region.  You can find your blog id under “My Sites->Network Admin->Sites”.

 

  • If you hover over the “Edit” link you will see the full link “https://www.example.com/wp-admin/network/site-info.php?id=1“.  This “id=1” is your site id.
  • Now that you know your site id, you can set up the two URLs correctly:
    • If the loaded page is from your first site, then you have to create the second site URL.  For example, if your second site is for the “AU”, you have to create that URL by replacing the “.com” with “.com/au”.
    • If the loaded page is from your second site, then you have to create the first site URL.  For example, if your first site is for “US”, then you have to create that URL by replacing the “.com/au” with “.com”.
  • You should also change the hreflang=”en-us” at the end of each tag with the correct language and country codes.
  • Finally, add this code to your “functions.php” file in your active theme.

Obviously, in my example I am using “US” and “AU” but you can substitute these for any regions you need.

Conclusion

The regional targeting of websites for regional search engines turned out to be more complicated than I had anticipated and I could not find a simple solution for the WooCommerce Multisite set up I had.  However, a little research and some code solved it in a relatively simple fashion.

I hope this article helps some of you set up your sites correctly from an SEO perspective so you can rank the different sites on different search engines accordingly.  As always please comment below with any feedback and let me know if creating a new plugin that implements this solution automatically would be valuable to you.

Leave a Reply

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