Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 7 replies, has 3 voices.

Last updated by epa-villa-arsonE 4 years ago.

Assisted by: Bobby.

Author Posts
March 20, 2020 at 9:46 pm #5730861

gulshanK

Tell us what you are trying to do?
- I am checking source code to find if hreflang is there or not.

Is there any documentation that you are following?
- No.

Is there a similar example that we can see?
- Please see the homepage source code at view-source:hidden link

March 20, 2020 at 11:12 pm #5730951

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi There,

1. Please verify that your page has been 100% translated, once it is then the hreflang will populate

2. Go to WPML->languages->SEO Options-> Display alternative languages in the HEAD section -> "As Early as possible"

Let me know your results, please.

March 21, 2020 at 9:45 am #5732501

gulshanK

Hello!

1. Done, I tested again at fresh WordPress. Ref: [removed]
2. It's already in "As Early as possible" settings.

Thanks

March 21, 2020 at 7:04 pm #5733913

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

I would like to request temporary access (wp-admin and FTP) to your site to test the issue.
(preferably to a test site where the problem has been replicated if possible)

**Before we proceed I recommend taking FULL BACKUP of your database and your website.**
I often use the Duplicator plugin for this purpose: http://wordpress.org/plugins/duplicator/

You will find the needed fields for this below the comment area when you log in to leave your next reply.
The information you enter is private which means only you and I have access to it.

NOTE: If access to the live site is not possible and the staging site does not exist please provide me with a duplicator package created with the duplicator plugin.

Thank you,
Bobby

March 23, 2020 at 4:51 pm #5743889

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Thank you for the access details!

I have removed your debug information from your previous reply.

Please review the following URL's source code and notice the hreflang is showing as expected for both languages.

The reason you are not seeing it on your homepage is that it is the WordPress archive, the blog posts are being shown on your homepage but not assigned to an existing page, therefore it is expected for 'hreflang' to not show.

This is the way WordPress works and is not a bug with WPML, even without WPML you wouldn't see the hreflang in the archive.

If you instead create a page called "Blog", translate it and then go to WP->Reading->Assign a static page for homepage and a page for the blog then the hreflangs will show.

March 23, 2020 at 5:52 pm #5744335

gulshanK

Hi again!

Please remove mentioned URL and screenshot. That's not required. I understood.

I did not received solution as expected what I feel a plugin should do instead expressing technical limitation, disappointed. Anways, Thanks for trying to help me.

Here's an alternative solution that I discovered. Thanks to dev Tom's theme: GeneratePress - Elements plugin, allow me to manually written hreflang code just for the Homepage as page rule.

Thanks
Sincerely,
G

March 23, 2020 at 6:21 pm #5744509

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

The screenshot and URL has been removed.

Please note that this is a WordPress limitation and not a WPML one.

Thank you for sharing your solution as this could help other users that might experience this.

January 10, 2021 at 7:59 pm #7810899

epa-villa-arsonE

For People passing by and facing the same issue, here is a piece of code you can put in your functions.php theme file to add hreflang tags on blog page :

/**
* Add Hreflang Link on Blog Page
* @hooks on wp_head
* @return string 
* Author : Afterglow Web Agency
*/
function afg_hreflangOnBlog() {
    if(!function_exists('icl_get_languages')) return;

    if(is_home()) {
        $defaultLanguage = apply_filters('wpml_default_language', NULL );
        $siteLanguages = icl_get_languages('skip_missing=1&orderby=code');
        
        foreach ($siteLanguages as $l) {
            $code = $l['language_code'];
            echo $code != $defaultLanguage ? 
                '<link rel="alternate" hreflang="'.$code.'" href="'.get_post_type_archive_link( 'post' ).'/'.$code.'/">' 
                : 
                '<link rel="alternate" hreflang="'.$code.'" href="'.get_post_type_archive_link( 'post' ).'">';
        }
    }
}

add_Action( 'wp_head', 'afg_hreflangOnBlog');

This code will automatically populate all the hreflang tags on default WordPress blog page. Regardless it is the front page or an inner page.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.