Mind your Language!
A practical guide to implementing ¡®proper¡¯ language encoding on multilingual WordPress websites
Presented at WordCamp Birmingham 2015 By Doug Lawrence and Belinda Mustoe
1 of 26
Download to read offline
More Related Content
Mind your language! A practical guide to implementing ¡®proper¡¯ language encoding on multilingual WordPress websites
1. douglawrence.com
helping you grow internationally
languages | sales | web | technology
Mind your Language!
A practical guide to implementing
¡®proper¡¯ language encoding on
multilingual WordPress websites
2. douglawrence.com
helping you grow internationally
languages | sales | web | technology
Intro
? 2 locales
? Doug Lawrence theory and benefits (en-gb)
? Belinda Mustoe implementation (en-php)
? Questions (for the audience)
3. douglawrence.com
helping you grow internationally
languages | sales | web | technology
Multilingual website
? Website in more than one language
? Website in a ¡®second¡¯ language
? Translation
? Larger audience (domestic and international)
? Added value services
? Potential new clients
? Growth in international trade
4. douglawrence.com
helping you grow internationally
languages | sales | web | technology
Language encoding benefits
? Good practice
? May help with accessibility
? Google Webmaster tools
? Search Engine Optimization
? Duplicate content (US/EN/AU)
? Default WordPress ¡®en-US¡¯ on UK sites just
looks cruddy! ;)
11. douglawrence.com
helping you grow internationally
languages | sales | web | technology
Problem
? Many different languages ¨C with the ability to
add more easily
? Not all pages have equivalents in other
languages, so need to add them on page by
page basis.
For Example:
<link rel="alternate" hreflang="en" href="http://douglawrence.com" />
<link rel="alternate" hreflang="ru-ru" href="http://douglaslawrence.ru" />
12. douglawrence.com
helping you grow internationally
languages | sales | web | technology
Solution
? Custom Meta Boxes with href Langs on each
page, repeater field.
13. douglawrence.com
helping you grow internationally
languages | sales | web | technology
How?
? Create two meta boxes in the WP admin using
fav method (I used CMB2)
17. douglawrence.com
helping you grow internationally
languages | sales | web | technology
Problem
1. Not using the Genesis framework
2. Only has two sites, no need for confusing adding
of boxes (too much flexibility)
3. Had to add href Langs to WooCommerce
product category pages
4. With 100+ pages adding a href lang for current
page manually would be very time consuming.
5. Is a complicated theme, probably better to add
it as a plugin
18. douglawrence.com
helping you grow internationally
languages | sales | web | technology
Solution
1. Not using Genesis Framework
add_action('wp_head','href_lang_output', 1);
More info here:
http://codex.wordpress.org/Plugin_API/Action_Reference/wp_head
19. douglawrence.com
helping you grow internationally
languages | sales | web | technology
Only one Meta box
? Only has two sites, no need for confusing
adding of boxes (too much flexibility)
20. douglawrence.com
helping you grow internationally
languages | sales | web | technology
Product Cat Pages
? Had to add href Langs to WooCommerce
product category pages
? CMB allows you to add data to Taxonomy
pages.
21. douglawrence.com
helping you grow internationally
languages | sales | web | technology
Get current Page URL
How to get current page automatically?
Pages & Blog Posts:
get_permalink();
Archive (& Product Archive) Pages:
$obj = get_queried_object();
get_term_link( $obj, $obj->taxonomy );
Author Pages:
get_author_posts_url( get_query_var( 'author' ), get_query_var( 'author_name' ) );
Shop page:
get_permalink( woocommerce_get_page_id( 'shop' ) );
25. douglawrence.com
helping you grow internationally
languages | sales | web | technology
Useful links
? Google Webmaster tools links:
? Use hreflang for language and regional URLs
https://support.google.com/webmasters/answer/189077?hl=en
? Country targeting
https://support.google.com/webmasters/answer/62399?hl=en
? Geotargetable domains
https://support.google.com/webmasters/answer/1347922?hl=en
? Wp head:
http://codex.wordpress.org/Plugin_API/Action_Reference/wp_head
26. douglawrence.com
helping you grow internationally
languages | sales | web | technology
Thank you
§³§á§Ñ§ã§Ú§Ò§à
лл
www.verytwisty.com www.douglawrence.com
Editor's Notes
#12: Put some tags into the header of the page
Rel = ¡°alternative¡± ¨C Tells google there¡¯s an alternative page avaiable
hreflang= language code ¨C tells google which languages are avaiable
href ¨C the link the alternative language page
#14: One meta box for the language one for the URL
#15: Create a php file called href-lang.php.
Gets the meta boxes on each page and loops through them
Outputs the html
#16: As using genesis framework added an action in the functions to
genesis_meta
Outputs the HTML at the top of the page
#17: Unusual in the both site are in English, but one in US english and one in UK english
Wanted people in the US to land on the US site, not the UK site when googling her website
Added Geotargeting and href langs to try and achieve this.
#19: WP has an action which you can use to modify the head
Call the function and set the priority, which in this case is 1
More information about wp_head can be found on the codex
#20: This is a screenshot of the UK site.
Only one metabox to paste in the alternative US URL
This simplifies it for the website owner
#21: Woocommerce uses Category Archive pages to display the list of products, so needed to add alternative href langs to these pages too.
#22: On each page we want to add a href lang tag with that site¡¯s language plus the alternative language is it¡¯s available.
For this site¡¯s language need to find the current page url, for the alternative we need to look it up from the meta boxes we created earlier.
Also we need to support this for a variety of different pages.
Looked at how Yoast SEO got the current page url for every page. (because it can be quite tricky).
#25: On the uk site the uk_url is the current page¡¯s url and the us_url is the metabox value. This is reversed on the US site.
X-default ¨C the default language
En-gb ¨C is the type of British English
En-us is US english
EN-ca is not really canadian english, but she wanted to direct Canadians to the US, not the UK site.