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 14 replies, has 2 voices.

Last updated by igorman 2 weeks, 2 days ago.

Assigned support staff: Bruno.

Author Posts
September 4, 2018 at 9:46 am #2702630

igorman

After updating (4.0.6, but maybe with one or two subversion above) i've noticed that alternate link disappeared in head section only on front page of my website.
I have disabled all not-wpml plugins and the problem persist.
Language switcher is working on frontpage, and the availables languages are present.

Could you give me some hints to check something?

September 4, 2018 at 10:19 am #2702795

igorman

The problem is introduced with your latest version of
/sitepress-multilingual-cms/classes/seo/class-wpml-seo-headlangs.php

I suppose that the problem is originated because the theme not declare correctly the front page

September 4, 2018 at 10:40 am #2702888

igorman

I have isolated problem in your

private function must_render( $languages )

Now i try to find a solution. I don't know if this is a bug or a theme related issue

September 4, 2018 at 1:53 pm #2703571

igorman

I've fix disabling your new $wpml_queried_object and reintroducing some of the old code

	private function must_render( $languages ) {
		$must_render         = false;
//		$wpml_queried_object = $this->queried_object_factory->create();
		$post          = $this->sitepress->get_wp_api()->get_post();

		$has_languages = is_array( $languages ) && count( $languages ) > 0;

		if (
//			$wpml_queried_object->has_object()
			$post
			&& $has_languages
			&& ! $this->sitepress->get_wp_api()->is_paged()
		) {

//			if ( $wpml_queried_object->is_instance_of_post() ) {
				/** @var WP_Post $queried_object */
//				$post_id = $wpml_queried_object->get_id();
			$post_id = $post ? $post->ID : false;

				$is_single_or_page = $this->sitepress->get_wp_api()->is_single() || $this->sitepress->get_wp_api()->is_page();
				$is_published      = $is_single_or_page
				                     && $post_id
				                     && $this->sitepress->get_wp_api()->get_post_status( $post_id ) === 'publish';

//				$must_render = $this->sitepress->is_translated_post_type( $wpml_queried_object->get_post_type() )
				$must_render = $this->sitepress->is_translated_post_type( $post->post_type )
				               && ( $is_published || $this->is_home_front_or_archive_page() );
//			}

//			if ( $wpml_queried_object->is_instance_of_taxonomy() ) {
//				/** @var WP_Term $queried_object */
//				$must_render = $this->sitepress->is_translated_taxonomy( $wpml_queried_object->get_taxonomy() );
//			}
//			if ( $wpml_queried_object->is_instance_of_post_type() ) {
//				/** @var WP_Post_Type $queried_object */
//				$must_render = $this->sitepress->is_translated_post_type( $wpml_queried_object->get_post_type_name() );
//			}
		}

		return $must_render;
	}

Do you have any idea why the new code not works on front page?

September 4, 2018 at 7:25 pm #2704560

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Thank you for contacting us.

I would be very happy to help you but I didn't fully understand what is the issue.

Can you please elaborate a little more so I can better understand? Sometimes screenshots illustrating what you mean may go a long way to clarify what words fail to transmit so if you like make use of "upload an image" below the comment area.

Also, what step-by-step should I follow to see/replicate the problem that you are reporting?

Thank you.

September 5, 2018 at 8:15 am #2705845

igorman

With your latest version (4.0.6) the function you have modified (see above... private function must_render) doesn't show the alternate href link in head section of home page.
I mean this code.

<link rel="alternate" hreflang="en" href="<em><u>hidden link</u></em>" />
<link rel="alternate" hreflang="it" href="<em><u>hidden link</u></em>" />

Now you can see it because i have fix it with the code above (in my previous reply).

Maybe this is related with theme that require to set "your latest post" for the homepage in wordpress settings.
How to replicate
You can activate the "href" link in your SEO section of WPML and see if this happens in themes which require "your latest post" for the homepage.

I have noticed this problem only in homepage (frontpage) of website.

September 5, 2018 at 8:30 am #2705890

igorman

I think that this object
$wpml_queried_object
you have introduced in the new version, for some reasons doesn't work with frontpage-homepage of my theme (and perhaps others)

September 5, 2018 at 9:02 pm #2708741

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Thank you for the explanation. Please, could you send me the theme that you are using so I can test it?

That way, I can forward this to our developers so they can check. At the moment, testing with the default theme of these SEO options and using the setting in Settings > Reading, I could not replicate the problem. Maybe this is a compatibility issue.

You can host the theme on some file server like Google Drive or Dropbox and send me the link so I can download the theme and test it. Your next answer will be private.

Thank you.

September 6, 2018 at 4:24 pm #2711703

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Thank you. This seems to be a compatibility issue with your theme. This is because the homepage does not have a translation page. The translation is done only using String Translation. For this reason, WPML does not identify a page in the secondary language and does not display hreflang tags.

To ensure that this theme is made compatible with WPML we need to contact the theme author and work with him on resolving the issue.

I have forwarded the details to our Themes & Plugins Compatibility Team and they will contact the author. Our Compatibility Team will work with the author of the plugin for this to work properly.

Please note that this process may take a while as it depends on how soon the author will reply to our efforts to contact him.

Thank you.

September 6, 2018 at 4:54 pm #2711764

igorman

Thanks for your reply.
In the meantime do you think is it safe to apply the fix i have copied above?

September 6, 2018 at 6:45 pm #2712055

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Apparently, this should not cause problems, but be aware that if you update WPML, this will be overwritten.

Also note that as this is a compatibility issue in the future, this is probably going to be fixed in your theme (with some custom coding).

Thank you.

September 17, 2018 at 2:11 pm #2741327

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Sorry for the delay. Our compatibility team suggested the following steps as a workaround:

- Open the file wp-content/plugins/sitepress-multilingual-cms/classes/seo/class-wpml-seo-headlangs.php on method private function must_render
- Before the return $must_render;
- Insert these lines:

if ( $this->sitepress->get_wp_api()->is_front_page() ) {
	$must_render = true;
}

- For example:

......
			if ( $wpml_queried_object->is_instance_of_post_type() ) {
				/** @var WP_Post_Type $queried_object */
				$must_render = $this->sitepress->is_translated_post_type( $wpml_queried_object->get_post_type_name() );
			}
		}

		// fix homepage hreflang
		if ( $this->sitepress->get_wp_api()->is_front_page() ) {
			$must_render = true;
		}

		return $must_render;
	}

After following these steps this should work correctly as well.

Thank you.

October 2, 2019 at 3:54 pm #4681887

igorman

Hi
With the latest 4.2.9 version of WPML Multilingual CMS plugin the following file has been removed
/sitepress-multilingual-cms/classes/seo/class-wpml-seo-headlangs.php
As i need to apply the hack above, where can i find it on the new release ?

October 2, 2019 at 4:20 pm #4682187

igorman

I have downloaded ZIP file from your website and i can see that here the "seo" folder is still present... why does it disappeared from plugin automatic update?

PS.
Sorry... the ftp client did not refresh the folder structure and i was not able to see it

October 2, 2019 at 4:24 pm #4682213

igorman

My issue is resolved now. Thank you!