How to manually add meta tag (meta language) for multi-language sites in C5 dashboard

Permalink 1 user found helpful
In multi-language sites i need to get meta tag for different sites. In dashboard, we can get url-name specification, page-selection and favicon. Along with that i need to add meta tag - language. this can be done through php function. So kindly help me with this... -> 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.

1 Attachment

View Replies:
getsupport replied on at Permalink Reply
Mainio replied on at Permalink Reply
If the multilingual add-on is installed I think it's better to use the built-in functions within it.

I.e. defining the language code
$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:
$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 ?>
BirgirGisla replied on at Permalink Reply

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.

maxence replied on at Permalink Reply
Here is a simple piece of code (5.7.X) to list all alternate pages for google.
$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; ?>" />