Recently one of my international clients wanted a second website to target customers in the US, while still retaining the SEO juice of the original website. For websites that have different subdomains or top-level domains with similar or translated content, you can tell search engines that these websites are linked. How? With hreflang tags in the header!
Using WordPress Multisite, it’s easy to have different websites made for the regions or languages you want to target. Implementing the hreflang tags will require a plugin and some database work, but overall it’s an easy process.
HREFLANG Tags Pro
For the easiest management of hreflang tags for WordPress Multisite, go for one with a bulk editor. HREFLANG Tags Pro’s bulk editor lets you quickly set up your posts and pages, and even custom post types, with the tags needed to connect your different sites together. For this blog post, we’ll only be using 2 sites to connect with hreflang tags, but you can add as many as you need with the plugin’s bulk editor.
After purchasing the plugin and obtaining the plugin license, download the plugin and install it on your WordPress Multisite. Activate it for the network, then go into your main site’s dashboard. There you will see “Hreflang Tags” in the admin sidebar. Click on it to access the settings. Here you will be able to activate the post types you need to match up across each site. Remember, the hreflang tag is a signal to search engines that the page has the same or similar content on one of your other websites. If the page is completely unique, you don’t and shouldn’t set the hreflang tag for it. So if a custom post type has completely unique content, you don’t need to enable hreflang tags for it.
After you choose which post types to use, go on to the Bulk Editor tab. Here you will see all of the posts, pages, and CPTs that the plugin can access. First though, we need to set the base hreflang tags.
A little note on this before we continue! From here on out, we are assuming you have a WordPress Multisite with at least 2 websites. We are also assuming that the 2nd site is a copy of the 1st, with minor changes to titles, text, images, etc. but all or most of the permalink slugs are expected to be the same across all sites. If your permalink slugs are completely different, this strategy is not for you as you will have to do the hreflang tags individually. If you have not changed permalinks across your sites, or if you’ve only changed a few, then let’s continue.
- Input {get_permalink} into the Alternative URL field. Then choose the language of the current site.
- For each additional site you have, press the + button. Repeat step #1 by using {get_permalink} in the Alternative URL field every time (we will update the domain in the database soon). Set the language for each one you add.
- When you are done, press the “Apply to All” button. Then be patient 🙂 It will automatically apply your hreflang tags to all of the posts, pages and CPTS that were enabled in the settings.
Using {get_permalink} in the bulk editor will let WordPress do its thing and auto-fill all of the URLs with their current permalinks. Next we’ll tackle how to update all of those permalinks to have the proper domain or subdomain.
Search and Replace in the Database
This next step will require you to have access to the database. You can do this with phpMyAdmin or with a plugin. Basically we need to update the values in the database to have the proper domain for the hreflang tags.
Let’s say we have siteone.com and sitetwo.com as our websites, with site IDs 1 and 2 respectively. Our WordPress table prefix is wp_tbl for this example. Siteone.com will be our English (Canada) website and sitetwo.com will be our English (US) website.
We open up our database in phpMyAdmin, go to the SQL tab, and put this in:
UPDATE wp_tbl_1_postmeta SET meta_value = REPLACE(meta_value,'siteone.com','sitetwo.com') WHERE meta_key = 'hreflang-en_US' AND meta_value LIKE '%siteone.com%';
Then press “Go”. What happens? All of the meta values for the US hreflang tags for siteone.com will be updated to point to sitetwo.com as the US website. As an example, http://siteone.com/about-us/ will have http://sitetwo.com/about-us/ set in the hreflang tags as the US version of the page.
We then have to do the same for site 2, but changing the site ID and the language tag:
UPDATE wp_tbl_2_postmeta SET meta_value = REPLACE(meta_value,'sitetwo.com','siteone.com') WHERE meta_key = 'hreflang-en_CA' AND meta_value LIKE '%sitetwo.com%';
Of course, change the site IDs, table prefix, domain names, and language tags to the ones appropriate for your circumstances.
If your permalink slugs are exactly the same across your sites, then you’re done! If you have a few that you’ve changed, you can set the hreflang tags individually by going to the page or post in the WordPress admin and scrolling down to the HREFLANG Tags Pro section in the editor. Update the hreflang tags there, and click Save. Do the same for the “alternate” page or post so they both have the correct information.