This class handles buidling the href lang tags across all of out international Wordpress implementations. The class instance is created in /global/partials/header-footer/header/header.php. The file is referenced in /wp-content/themes/theme/header.php - which is included in every international repo.
The function of the HrefLang class is to build the href lang meta tags on every page of the website. The class is called on every page, then queries the database and returns the countries that page exists on; building the links to that page in alternate regions and languages. This is done to provide search engines reference to the different international and language versions of the site. For example the href lang links for the "company" page would have the Spanish, Chinese, Australian and Singapore region links in the page so that if someone specific to that region was searching for a page, the appropriate link would be provided.
The entire implementation is accomplished by just instantiating the class. The whole process takes place in the constructor of the class. Stepping through the constructor is enough to understand how the class works. Basically when the class is instantiated the Href lang links are output.
<!-- LISTING HREFLANG ALTERNATIVE PAGES --> <link rel="alternate" hreflang="en" href="http://domain.com/" /> <link rel="alternate" hreflang="en-AU" href="http://domain.com/au/" /> <link rel="alternate" hreflang="es" href="http://domain.com/es/" /> <link rel="alternate" hreflang="en-SG" href="http://domain.com/sg/" /> <link rel="alternate" hreflang="zh-CN" href="http://domain.com/zh/" /> <!-- END HREFLANG -->The page loads and hits the class instance. The constructor takes the wordpress $post object - it uses this to make sure that the page being loaded is actually a wordpress page and not just and empty route. Once the page is established it does the following
This class requires 2 tables: href_lang_page and href_lang_pages. href_lang_page includes the page_id, slug, and href_date. The second table href_lang_pages includes id, page_id and country