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

Description
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

Please download to get full document.

View again

of 26
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information
Category:

Software

Publish on:

Views: 0 | Pages: 26

Extension: PDF | Download: 0

Share
Transcript
  • 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 – 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
  • Related Search
    Similar documents
    We Need Your Support
    Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

    Thanks to everyone for your continued support.

    No, Thanks