• Resolved maryb1

    (@maryb1)


    Hello,

    The languages on my website are set as en_CA an fr_CA. The hreflang tags generated by multilingualpress reflect that. However, according to Google, when you have a country-based language variation (en_CA) in your hreflang tags, you should also always include a general version (en). So in addition to:

    link rel=”alternate” hreflang=”en-CA” href=”…”
    link rel=”alternate” hreflang=”fr-CA” href=”…”

    I would like to add

    link rel=”alternate” hreflang=”en” href=”…”
    link rel=”alternate” hreflang=”fr” href=”…”

    Is that possible with multilingual press?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @maryb1,

    yes you can add those by including a little snippet in your child theme within the file functions.php or create a simple plugin and upload it but nothing you can do with just change a setting unfortunately.

    Here the code

    
    add_filter('multilingualpress.hreflang_translations', function($translations) {
        $generalTranslations = [];
        foreach($translations as $lang => $url) {
            $code = substr($lang, 0, strpos($lang, '-'));
            $code and $generalTranslations[$code] = $url;
        }
    
        $translations = array_merge($translations, $generalTranslations);
        return $translations;
    });
    

    Note when you copy it remember to keep an eye on the quotes characters, some system may copy the wrong quotes.

    If you need help let me know

    • This reply was modified 5 years, 5 months ago by Guido Scialfa. Reason: Wrong code tag
    Thread Starter maryb1

    (@maryb1)

    Hello Guido,

    Thanks so much, that worked! ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding custom hreflang tags’ is closed to new replies.