Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi there,

    does your theme call wp_head()?

    Kind regards,
    Thorsten

    Thread Starter mbain

    (@markcbain)

    Thanks for your response, Thorsten. Yes, the theme does call wp_head()

    Thread Starter mbain

    (@markcbain)

    Sorry, I have worked out the issue. I was expecting the hreflang meta to show as soon as the plugin was activated, but I see that you have to manually associate posts first. Having over 300 posts, I was hoping to avoid manual work!

    Thread Starter mbain

    (@markcbain)

    For anyone interested, here’s how I did it in the end.

    In functions.php,

    function my_hreflang_tags() {
    
        /*
         *   Add hreflang tags to head
         */
    
        // Get the permalink
        $the_old_link = get_permalink();
    
        // Create 2 localized versions of the permalink for use in the hreflang tag
    
        $the_new_link_gb = str_replace( '/gb', '/us', $the_old_link );
        $the_new_link_us = str_replace( '/us', '/gb', $the_old_link );
    
        // Print it out
    
        echo '<!-- Hreflang tags -->';
        echo '<link rel="alternate" hreflang="en-US" href="' . $the_new_link_us . '">';
        echo '<link rel="alternate" hreflang="en-GB" href="' . $the_new_link_gb . '">';
    
    }
    add_action( 'wp_head', 'my_hreflang_tags', 1 );
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Automatic hreflang tags’ is closed to new replies.