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 2 voices.

Last updated by Jesse 1 year, 11 months ago.

Assisted by: Bobby.

Author Posts
May 24, 2022 at 4:22 pm #11295373

Jesse

Hello

I am using the Astra theme pro and I never really got any issue with the WPML plugin.

We are trying this time to add a dropdown with 3 diffirent languages but the dropdown seem to not work and just show all the languages vertical.

I saw on this thread (https://wpml.org/forums/topic/2-issues-with-the-language-switch-selector/) that it was a knowed issue? Any change you found a work around?

Thank you and have a great day!

supportWPML.JPG
May 24, 2022 at 7:05 pm #11296535

Bobby
Supporter

Languages: English (English )

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

Hello,

Please try the following workaround:

Go to: \wp-content\plugins\sitepress-multilingual-cms\classes\class-wpml-file.php

change the function get_uri_from_path to:

public function get_uri_from_path( $path ) {
		$base = null;

		if ( $this->wp_api->defined( 'WP_CONTENT_DIR' ) && $this->wp_api->defined( 'WP_CONTENT_URL' ) ) {
			$base_path = $this->fix_dir_separator( $this->wp_api->constant( 'WP_CONTENT_DIR' ) );

			if ( 0 === strpos( $path, $base_path ) ) {
				$base = array(
					'path' => $base_path,
					'uri'  => $this->wp_api->constant( 'WP_CONTENT_URL' ),
				);
			}
		}

		if ( ! $base ) {
			$base = array(
				'path' => $this->wp_api->constant( 'ABSPATH' ),
				'uri'  => site_url(),
			);
			if ( 0 !== strpos( $path, $base_path ))
			{
				$search = (WPML_PLUGIN_PATH);
				$pathexplode = explode($this->wp_api->constant( 'DIRECTORY_SEPARATOR' ), WPML_PLUGIN_PATH);
				$pathexplode = array_slice($pathexplode, -3, 3, false);
				$replace = $pathexplode[0] .$this->wp_api->constant( 'DIRECTORY_SEPARATOR' ) . $pathexplode[1].$this->wp_api->constant( 'DIRECTORY_SEPARATOR' ).WPML_PLUGIN_FOLDER;
				$base["path"] = str_replace ($replace, "", $search);
			}
		}

		$base['uri']   = preg_replace( '/(^https?:)/', '', $base['uri'] );
		$relative_path = substr( $path, strlen( $base['path'] ) );
		$relative_path = str_replace( array( '/', '\\' ), '/', $relative_path );
		$relative_path = ltrim( $relative_path, '/' );

		return trailingslashit( $base['uri'] ) . $relative_path;
	}

NOTE: Always have a recent and working backup before making any changes recommended by our team or a 3rd party

Let me know your results, please.

May 24, 2022 at 7:53 pm #11296769

Jesse

Hello!

Thank you for your quick answer, sadly, the issue is still present.

Could it be an issue with Elementor Pro or any other code that we have in our Function.php files?

Cordialy,
Jesse

May 25, 2022 at 12:40 am #11297935

Bobby
Supporter

Languages: English (English )

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

Hi Jesse,

1. When you inspect your front end do you see any errors in your console? If yes share a screenshot with me.

2. How are you adding the language switcher? Are you adding it through WPML->languages or using an elementor template and shortcode?

May 25, 2022 at 1:00 am #11297941

Jesse

Hello again!

1. there is only one error in the console, you can see in the screenshot that I have provided

2. we are using the Langage switcher widget module

thank you for your time!

widget.JPG
error.JPG
May 25, 2022 at 3:14 pm #11307453

Jesse

Hello

I have found a way to make the Dropdown work by using the "language selector in menu" option instead of the "in a widget" one. Does that mean that the issue could be with The widget fonctionnality?

Because it's still something that would need to be solved for futur project, since we might need to put the language selector at different places.

Thank you again for your time!

Cordialy,
Jesse

May 25, 2022 at 7:07 pm #11309321

Bobby
Supporter

Languages: English (English )

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

Hi Jesse,

Glad to hear you were able to resolve this.

In the case of adding the language switcher in custom locations, I would suggest using the following code in order to place it as it allows you to place the switcher in any location.

https://wpml.org/documentation/getting-started-guide/language-setup/language-switcher-options/#custom-locations

May 25, 2022 at 8:18 pm #11309749

Jesse

i'll look into the procedure, thank you for your help and your time! I wish you a great day

My issue is resolved now.

Cordialy
Jesse

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