ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
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
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)
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
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! ;)
douglawrence.com
helping you grow internationally
languages | sales | web | technology
Google webmaster tools
douglawrence.com
helping you grow internationally
languages | sales | web | technology
Google webmaster tools
douglawrence.com
helping you grow internationally
languages | sales | web | technology
Google webmaster tools
douglawrence.com
helping you grow internationally
languages | sales | web | technology
Google webmaster tools
douglawrence.com
helping you grow internationally
languages | sales | web | technology
Google webmaster tools
douglawrence.com
helping you grow internationally
languages | sales | web | technology
Adding hreflangs to Doug¡¯s Sites
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" />
douglawrence.com
helping you grow internationally
languages | sales | web | technology
Solution
? Custom Meta Boxes with href Langs on each
page, repeater field.
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)
douglawrence.com
helping 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="<?php
echo $hrefurl; ?>" />
<?php } ?>
douglawrence.com
helping 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.com
helping you grow internationally
languages | sales | web | technology
Adding hreflangs to e-commerce sites
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
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
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)
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.
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' ) );
douglawrence.com
helping 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.com
helping 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.com
helping 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.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
douglawrence.com
helping you grow internationally
languages | sales | web | technology
Thank you
§³§á§Ñ§ã§Ú§Ò§à
лл
www.verytwisty.com www.douglawrence.com

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! ;)
  • 5. douglawrence.com helping you grow internationally languages | sales | web | technology Google webmaster tools
  • 6. douglawrence.com helping you grow internationally languages | sales | web | technology Google webmaster tools
  • 7. douglawrence.com helping you grow internationally languages | sales | web | technology Google webmaster tools
  • 8. douglawrence.com helping you grow internationally languages | sales | web | technology Google webmaster tools
  • 9. douglawrence.com helping you grow internationally languages | sales | web | technology Google webmaster tools
  • 10. douglawrence.com helping you grow internationally languages | sales | web | technology Adding hreflangs to Doug¡¯s Sites
  • 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)
  • 14. douglawrence.com helping 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="<?php echo $hrefurl; ?>" /> <?php } ?>
  • 15. douglawrence.com helping 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' );
  • 16. douglawrence.com helping you grow internationally languages | sales | web | technology Adding hreflangs to e-commerce sites
  • 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' ) );
  • 22. douglawrence.com helping 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(); }
  • 23. douglawrence.com helping 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;
  • 24. douglawrence.com helping 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; ?>
  • 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).
  • #23: Putting It all together.
  • #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.