mind your language! a practical guide to implementing ‘proper’ language encoding on multilingual...
TRANSCRIPT
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Mind your Language!
A practical guide to implementing ‘proper’ language encoding on
multilingual WordPress websites
douglawrence.comhelping 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)
douglawrence.comhelping 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
douglawrence.comhelping 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! ;)
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Google webmaster tools
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Google webmaster tools
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Google webmaster tools
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Google webmaster tools
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Google webmaster tools
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Adding hreflangs to Doug’s Sites
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Problem
• Many different languages – 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" />
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Solution
• Custom Meta Boxes with Href Langs on each page, repeater field.
douglawrence.comhelping you grow internationally
languages | sales | web | technology
How?
• Create two meta boxes in the WP admin using fav method (I used CMB2)
douglawrence.comhelping you grow internationally
languages | sales | web | technology
hreflang.php
<?php$entries = get_post_meta( get_the_ID(), 'href_repeat', true );
foreach ( (array) $entries as $key => $entry ) {
if ( isset( $entry['hreflang'] ) )$hreflang = esc_attr( $entry['hreflang'] );
if ( isset( $entry['href_url'] ) )$hrefurl = esc_html( $entry['href_url'] );
?><link rel="alternate" hreflang="<?php echo $hreflang; ?>" href="<?phpecho $hrefurl; ?>" />
<?php } ?>
douglawrence.comhelping you grow internationally
languages | sales | web | technology
functions.php
function include_href_lang() {
require(CHILD_DIR.'/hreflang.php');
}
add_action( 'genesis_meta', 'include_href_lang' );
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Adding hreflangs to e-commerce sites
douglawrence.comhelping 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 WooCommerceproduct 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
douglawrence.comhelping 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
douglawrence.comhelping 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)
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Product Cat Pages
• Had to add Href Langs to WooCommerceproduct category pages
• CMB allows you to add data to Taxonomy pages.
douglawrence.comhelping 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' ) );
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Get current Page URL
if( is_shop() ){
$current_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );
}
elseif ( is_author() ) {
$current_page_url = get_author_posts_url( get_query_var( 'author' ), get_query_var( 'author_name' ) );
}
elseif ( is_archive() ) {
$obj = get_queried_object();
$current_page_url = get_term_link( $obj, $obj->taxonomy );
}else{
$current_page_url = get_permalink();
}
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Getting Alternative URL
if ( is_archive() ):
// gets the Alternate URL of Taxonomy Page$obj = get_queried_object();
// Gets the Variables from the Taxonomy$taxonomy = 'product_cat';$term_id = $obj->term_id;$tax_data = Taxonomy_MetaData::get( $taxonomy, $term_id);$alt_url = $tax_data['tax_us_url'];
else:global $post;// Gets Alt Page URL$alt_url = get_post_meta( $post->ID, $prefix . 'us_url', true );
endif;
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Outputting the HTML
$us_url = esc_attr( $alt_url );
$uk_url = $current_page_url;
<?php if($uk_url): ?>
<link rel="alternate" href="<?php echo $uk_url; ?>" hreflang="x-default" />
<link rel="alternate" href="<?php echo $uk_url; ?>" hreflang="en-gb" />
<?php endif; ?>
<?php if($us_url): ?>
<link rel="alternate" href="<?php echo $us_url; ?>" hreflang="en-us" />
<link rel="alternate" href="<?php echo $us_url; ?>" hreflang="en-ca"/>
<?php endif; ?>
douglawrence.comhelping 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
douglawrence.comhelping you grow internationally
languages | sales | web | technology
Thank you Спасибо 谢谢
www.verytwisty.com www.douglawrence.com