Link slider button for different language - Polylang

Hi,

I’m able to translate the button titles, but I can’t find a way to update the links to the appropriate translated page. How or where can I change this?

Thank you
Nicole

Hello there,

You can translate the slide buttons depending on the current language displaying on the screen with jQuery code. Please try doing these steps:

  1. Install and activate the TC Custom JavaScript plugin
  2. Go To Appearance > Custom JavaScript
  3. Paste the following code into the provided box
    (function($){

      $.fn.translateSlideButton=function(t){var i=$.extend({slide:"",url:"",label:""},t);this.find(".main-slider .slider-item:nth-child("+i.slide+") .button").length&&this.find(".main-slider .slider-item:nth-child("+i.slide+") .button").attr("href",i.url).text(i.label)};

      /**
       * Buttons translation starts
      */

      // First slide button for FR
      $('[lang="fr-FR"]').translateSlideButton({
        slide: '1', // First slide
        url: 'http://yoursite.com/link',
        label: 'Button Text'
      });

      // Second slide button for FR
      $('[lang="fr-FR"]').translateSlideButton({
        slide: '2', // Second slide
        url: 'http://yoursite.com/link2',
        label: 'Button Text 2'
      });

      // Third slide button for FR
      $('[lang="fr-FR"]').translateSlideButton({
        slide: '3', // Second slide
        url: 'http://yoursite.com/link3',
        label: 'Button Text 3'
      });

      /**
       * Buttons translation ends
       */

    })(jQuery);

To translate the first button, duplicate and edit this code block:

    // First slide button for FR
    $('[lang="fr-FR"]').translateSlideButton({
      slide: '1', // First slide
      url: 'http://yoursite.com/link',
      label: 'Button Text'
    });

Change fr-FR to your language code attributed to the body tag. You can get it with the web browser’s inspector tool. On Firefox, right click and select Inspect Element.

52 AM

Then set the values for slide, url and label. To enable translation on the first slide, the slide value must be set to 1.

4 . Update
5 . Flush applied site cache as it usually blocks the code additions from taking effect in the front end. https://codex.wordpress.org/I_Make_Changes_and_Nothing_Happens

Regards,
Kharis

1 Like