Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client wants to ensure that when a user clicks on the 'FR' language switcher on their mobile site, they are not only taken to the French homepage but also immediately see the French pop-up menu.

Solution:
We recommend using custom JavaScript in combination with URL parameters or cookies to control the state of the menu. Here are the steps to achieve this:

1. Add a menu item with a specific class and href on the source page:

<li class="wpml-ls-slot-footer wpml-ls-item wpml-ls-item-fr wpml-ls-last-item wpml-ls-item-legacy-list-horizontal">
  <a href="https://www.dsmcuisines.be/testingpage-2-fr/" class="wpml-ls-link">
    <span class="wpml-ls-display">FR</span>
  </a>
</li>

2. Add the menu pop-up container with a specific ID on the target page:

<div class="dialog-widget dialog-lightbox-widget dialog-type-buttons dialog-type-lightbox elementor-popup-modal" id="elementor-popup-modal-70337" aria-modal="true" role="document" tabindex="0" style="display: none;">
  <!-- Content of your menu pop-up goes here -->
</div>

3. Use JavaScript to open the menu pop-up on the source page when the 'FR' menu item is clicked:

<script>
  function openMenuPopup() {
    const menuPopup = document.getElementById('elementor-popup-modal-70337');
    if (menuPopup) {
      menuPopup.style.display = 'block';
    }
  }

  const targetMenuItem = document.querySelector('li.wpml-ls-item-fr a[href="https://www.dsmcuisines.be/testingpage-2-fr/"]');

  if (targetMenuItem) {
    targetMenuItem.addEventListener('click', function(event) {
      event.preventDefault();
      openMenuPopup();
    });
  }
</script>

4. On the target page, check for the 'menu' parameter and open the menu if needed:

<script>
  function checkForMenuParameter() {
    const urlParams = new URLSearchParams(window.location.search);
    const isMenuOpen = urlParams.has('menu');

    if (isMenuOpen) {
      openMenuPopup();
    }
  }

  function openMenuPopup() {
    const menuPopup = document.getElementById('elementor-popup-modal-70337');
    if (menuPopup) {
      menuPopup.style.display = 'block';
    }
  }

  checkForMenuParameter();
</script>

Please note that this is a general guide and the code needs to be adjusted to fit the specific structure and requirements of your website. If this solution does not seem relevant or if you need further assistance, we recommend consulting with one of our WPML contractors for custom work.

If this solution does not look relevant, please open a new support ticket.

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.

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Bruno Kos 1 year, 3 months ago.

Assisted by: Bruno Kos.

Author Posts
January 25, 2024 at 10:02 am #15225343

matthiasR-28

If you go to hidden link

This is a page only to see in mobile version. If you go to the page, you see the language switcher under the logo (NL - FR). My question is: Is it possible if you click on FR that you go to the FR homepage + the FR pop-up menu appears directly?

Thanks in advance

Kind regards

January 25, 2024 at 10:16 am #15225385

Bruno Kos
WPML Supporter since 12/2018

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

Thank you for contacting WPML support!

Can you clarify this a bit more:

**
+ the FR pop-up menu appears directly?
**

What do you mean by this, any screenshots or examples for us to share?

Regards,
Bruno Kos

January 25, 2024 at 10:26 am #15225429

matthiasR-28

If you click on the homepage NL and you go to the menu icon. You see the pop-up full screen menu in Netherlands with logo DSM Keukens. If you click on FR, you go to the FR homepage.

But we want: If you click on the FR button, you see immediately the pop-up menu FR (see screenshot) and the homepage FR is after the pop-up.

Kind regards

IMG_1339.PNG
IMG_1338.PNG
IMG_1337.PNG
January 25, 2024 at 11:04 am #15225605

Bruno Kos
WPML Supporter since 12/2018

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+02:00)

There is no such option and WPML so it will require custom work. You can have a look with our https://wpml.org/contractors/ to achieve this as we cannot assist with this.

I believe you can use JavaScript though in combination with URL parameters or cookies to store and control the state of the menu. Something like this may be a general idea:

On the source page (where the menu item is clicked):

<!-- Add the menu item with a specific class and href -->
<li class="wpml-ls-slot-footer wpml-ls-item wpml-ls-item-fr wpml-ls-last-item wpml-ls-item-legacy-list-horizontal">
  <a href="<em><u>hidden link</u></em>" class="wpml-ls-link">
    <span class="wpml-ls-display">FR</span>
  </a>
</li>

On the target page (where the menu pop-up should appear):

<!-- Add the menu pop-up container with a specific ID -->
<div class="dialog-widget dialog-lightbox-widget dialog-type-buttons dialog-type-lightbox elementor-popup-modal" id="elementor-popup-modal-70337" aria-modal="true" role="document" tabindex="0" style="display: none;">
  <!-- Content of your menu pop-up goes here -->
</div>

In order to combine them, you would need some JavaScript Code. On the source page:

<script>
  // Function to open the menu pop-up
  function openMenuPopup() {
    const menuPopup = document.getElementById('elementor-popup-modal-70337');
    if (menuPopup) {
      menuPopup.style.display = 'block';
    }
  }

  // Find the <li> element with the class "wpml-ls-item-fr" and the specific href
  const targetMenuItem = document.querySelector('li.wpml-ls-item-fr a[href="<em><u>hidden link</u></em>"]');

  // Add a click event listener to the target menu item
  if (targetMenuItem) {
    targetMenuItem.addEventListener('click', function(event) {
      // Prevent the default link behavior to avoid navigating to the page
      event.preventDefault();

      // Add code here to set a flag or perform any additional actions if needed
      // Example: window.location.href = '<em><u>hidden link</u></em>';

      // Call the function to open the menu pop-up
      openMenuPopup();
    });
  }
</script>

On the target page:

<script>
  // Function to check for the 'menu' parameter and open the menu if needed
  function checkForMenuParameter() {
    const urlParams = new URLSearchParams(window.location.search);
    const isMenuOpen = urlParams.has('menu');

    if (isMenuOpen) {
      openMenuPopup();
    }
  }

  // Function to open the menu pop-up
  function openMenuPopup() {
    const menuPopup = document.getElementById('elementor-popup-modal-70337');
    if (menuPopup) {
      menuPopup.style.display = 'block';
    }
  }

  // Check for the 'menu' parameter and open the menu if needed when the page loads
  checkForMenuParameter();
</script>

Now, when you click the "FR" menu item on the source page, it should open the menu pop-up on the target page (`hidden link`) if you have implemented the code correctly.

Make sure to adjust the HTML and JavaScript code as needed to match your specific website's structure and requirements.

But this is just a general idea and I have not tested this - please consult our https://wpml.org/contractors/ for further checks and implementations.