Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mind your language! A practical guide to implementing ‘proper’ language encoding on multilingual WordPress websites

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

  • Be the first to comment

  • Be the first to like this

Mind your language! A practical guide to implementing ‘proper’ language encoding on multilingual WordPress websites

  1. 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. 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. 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. 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. 5. douglawrence.com helping you grow internationally languages | sales | web | technology Google webmaster tools
  6. 6. douglawrence.com helping you grow internationally languages | sales | web | technology Google webmaster tools
  7. 7. douglawrence.com helping you grow internationally languages | sales | web | technology Google webmaster tools
  8. 8. douglawrence.com helping you grow internationally languages | sales | web | technology Google webmaster tools
  9. 9. douglawrence.com helping you grow internationally languages | sales | web | technology Google webmaster tools
  10. 10. douglawrence.com helping you grow internationally languages | sales | web | technology Adding hreflangs to Doug’s Sites
  11. 11. douglawrence.com helping 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" />
  12. 12. douglawrence.com helping you grow internationally languages | sales | web | technology Solution • Custom Meta Boxes with Href Langs on each page, repeater field.
  13. 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. 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. 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. 16. douglawrence.com helping you grow internationally languages | sales | web | technology Adding hreflangs to e-commerce sites
  17. 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. 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. 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. 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. 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. 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. 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. 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. 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. 26. douglawrence.com helping you grow internationally languages | sales | web | technology Thank you Спасибо 谢谢 www.verytwisty.com www.douglawrence.com

×