Adding hreflang to my head without creating extra languages in WPML

370 Views Asked by At

I build a site with 4 languages:

  • Dutch
  • French
  • German
  • English

I did this with WPML. I want to make use of regions, for example en-US, en-GB, en-IE. WPML said I need to add 2 extra languages what would mean that only for the hreflang I need to have each page or product 3 times and also when a modification is needed it has to be done 3 times for each page or product.

So I wrote a little script which dynamically adds hreflang to my head:

add_action('wp_head', 'add_link_in_head');
function add_link_in_head()
{

    $url = get_the_permalink();
    $wpml_permalink = apply_filters( 'wpml_permalink', $url , 'en' );

        ?>
                <link rel="alternate" href="<?php echo $wpml_permalink; ?>" hreflang="en-gb" />
                <link rel="alternate" href="<?php echo $wpml_permalink; ?>" hreflang="en-us" />
                <link rel="alternate" href="<?php echo $wpml_permalink; ?>" hreflang="en-ie" />
        <?php
}

Because I do only have a WPML language en I am saying with this that this is page for en-gb, en-us and en-ie.

Is this a workable workaround instead of adding extra languages in WPML?

1

There are 1 best solutions below

0
On

I doubt this will work, since you're providing an identical URL for all 3 hreflang tags.

Since you don't have variation in content at each URL (it's one and the same URL), I suspect that this will likely confuse the crawler and might influence the ranking of your pages. The rel="alternate" part is meant to tell the crawler that the URL in each tag is an alternate version of the page - and you have an identical URL for all of them.

I suggest you test your hreflang tags with a testing tool such as this: https://technicalseo.com/tools/hreflang/