How to manually add meta tag (meta language) for multi-language sites in C5 dashboard
Permalink 1 user found helpfulhttps://github.com/rmxdave/multisite/blob/master/models/ms_router.ph... -> this is an example link, in which they get value for url, home page and favicon.
I just created a simple label to mention the language content type. But I didn't know to apply logic for that. This is the image for which i required php function for language!
Thanks in advance.
I.e. defining the language code
<?php $lang = "en"; // default if (class_exists('MultilingualSection') && is_object($ms = MultilingualSection::getCurrentSection())) { $lang = $ms->getLanguage(); } ?> <html lang="<?php echo $lang ?>">
And if you'd want to have the related language tags that Google suggests, do something like this:
<?php $nav = Loader::helper('navigation'); $ms = MultilingualSection::getCurrentSection(); // no need for this if you already do what's mentioned above foreach (MultilingualSection::getList() as $sect) : // EDIT: Actually I don't think this is needed. //if ($sect->getCollectionID() == $ms->getCollectionID()) continue; // no need to link the current language $rpID = $sect->getTranslatedPageID($c); if (!$rpID) continue; // no related page for this in the target language $rp = Page::getByID($rpID); if (!is_object($rp) || $rp->isError()) continue; // deleted page linked to this language ?> <link rel="alternate" hreflang="<?php echo str_replace("_", "-", strtolower($sect->getLocale())) ?>" href="<?php echo $nav->getLinkToCollection($rp, true) ?>" /> <?php endforeach ?>
https://support.google.com/webmasters/answer/189077?hl=en...
Thank you so much for sharing this code with the community. It does exactly what Google recommends for alternative languages and regional URL's. Really helpful when it comes to ensure proper SEO.
Birgir
<?php $sections = Concrete\Core\Multilingual\Page\Section\Section::getList(); $c = \Page::getCurrentPage(); foreach ($sections as $section) { $relatedID = $section->getTranslatedPageID($c); if ($relatedID) { $pc = \Page::getByID($relatedID); //$lang = $section->getLocale(); // locale $lang = $section->msLanguage; // lang only $href = $pc->cPath; ?> <link rel="alternate" hreflang="<?php echo $lang; ?>" href="<?php echo $href; ?>" /> <?php } }
Did something similar here:
http://www.concrete5.org/community/forums/usage/how-to-change-the-l...