0

I'm trying to disable an image link when the site navigates out of the original language. Its wordpress and I'm using Polylang to translate. The site is in Portuguese, English, Deutsh and French. I have a widget that is located in a common wrap no matter the language. That widget shows images with links to a pop-up commanded with a plugin that uses a class (class="modal-link") can't disable that class because it will break links in other pages. I need the links to disable when switching to English/Deutsh/French.

The code in the widget is like this:

<a class="modal-link" href="http://moldetefa.com/wp2018/index.php/pt2020/">
<img border="0" alt="Centro2020" src="http://moldetefa.com/wp2018/wp- 
content/uploads/2018/08/c2020.png"></a>
<a class="modal-link" href="http://moldetefa.com/wp2018/index.php/pt2020/">
<img border="0" alt="Portugal2020" src="http://moldetefa.com/wp2018/wp- 
content/uploads/2018/08/pt_2020.png"></a>
<a class="modal-link" href="http://moldetefa.com/wp2018/index.php/pt2020/">
<img border="0" alt="FEDR" src="http://moldetefa.com/wp2018/wp- 
content/uploads/2018/08/FEDR.png"></a>

This CSS works but I don't know how to call it just in a specific language

[href="http://moldetefa.com/wp2018/index.php/pt2020/"]{
pointer-events: none;
}

This CSS works for doing things under that language only, but I don't know how to write the code to disable that specific link.

:lang(en)   {

}

Just done this and it worked ! :O

:lang(en) > [href="http://moldetefa.com/wp2018/index.php/pt2020/"]{
pointer-events: none;
}   

Any thoughts? Thank's JF

JohnnyF
  • 5
  • 4

1 Answers1

0

What you can try, inside your functions.php file add a small function to check the current language and return something:

function check_languages($pt, $fr, $en, de) {
    $cuurent_language = get_locale();
    if($cuurent_language == 'pt_PT'){
        return $pt;
    }
    if($cuurent_language == 'fr_FR'){
        return $fr;
    }
    if($cuurent_language == 'en_GB'){
        return $en;
    }
    if($cuurent_language == 'de_DE'){
        return $de;
    }
}

Since there are more than 1 locale for English, French etc. you can check you current version of the chosen language inside Polilang - http://joxi.ru/Vm6ZjvEHDqeMkm and replace it in this example function if needed. Once you have this function added you can use it like:

<a class="<?=check_languages('modal-link', '', '', '');?>" href="http://moldetefa.com/wp2018/index.php/pt2020/">
<img border="0" alt="Centro2020" src="http://moldetefa.com/wp2018/wp- 
content/uploads/2018/08/c2020.png"></a>

So for Portuguese you'ill have modal class added, for the rest of the languages - nothing or whatever class you place. Another option I can think of is to use Polilang string translation (better than a custom function, if you have lots of strings in your templates that need to be translated) and register a string like:

<a class="<?pll_e('modal-link');?>" href="http://moldetefa.com/wp2018/index.php/pt2020/">
<img border="0" alt="Centro2020" src="http://moldetefa.com/wp2018/wp- 
content/uploads/2018/08/c2020.png"></a>

After this inside your string translation in Polilang you'll leave the class only for the Portuguese language. If you want to try with jQuery, at the end of your homepage template file add this:

<script>
    if($('html').attr('lang') !== 'pt-PT'){
      $(".modal-link").css("pointer-events", "none !important");
    }
<\script>
Angel Deykov
  • 1,199
  • 1
  • 9
  • 15
  • I tried to implement that Angel Deykov, but didn't worked. I think I don't have the skills at this moment to do so, still learning. Hoever :lang(en) > [href="http://moldetefa.com/wp2018/index.php/pt2020/"]{ pointer-events: none; } works but not in iExplorer. Can you guys help with that? – JohnnyF Sep 28 '18 at 13:17
  • Tried again and Actually this works ( Centro2020) but only deactivates de modal-link class. People still can click and open the page normally. The modal-link class its only for the page to appear in pop-up. But if I use a new class (.hidelink{ pointer-events: none; }) to hide pointer events it don't work – JohnnyF Sep 28 '18 at 14:14
  • Try to put !important after the none value in the css - .hidelink{ pointer-events: none !important; } – Angel Deykov Sep 30 '18 at 14:58
  • can you check in debugger and confirm that 'modal-link' class is replaced with 'hidelink' in other languages ? – Angel Deykov Oct 01 '18 at 14:41
  • sorry I've tried but I don't know how to do that :/ – JohnnyF Oct 02 '18 at 13:20
  • can you put a link to your page, so I can take a look at it ? – Angel Deykov Oct 02 '18 at 13:59
  • http://moldetefa.com/wp2018/ (the code is in the bottom image that represents CENTRO2020, this image is inserted with an widget) thanks (note that this option ' Centro2020' will not do because polylang don't translate this specific string. – JohnnyF Oct 02 '18 at 15:37
  • Ok I see you try to put the php as a class but it cannot work in this way Put your modal class back + 1 custom class like 'deactivate-modal' Your css approach is better, since I now understand you cannot use php al along with this widget. Now try to put both of these: html:lang(fr) a.deactivate-modal{ pointer-events: none; } html[lang="fr"] a.deactivate-modal{ pointer-events: none; } – Angel Deykov Oct 03 '18 at 07:02
  • @ this point I removed functions.php code, removed code from the widget back to "modal-link" and added in the Custom CSS this for all 3 languages: (:lang(fr) > [href="http://moldetefa.com/wp2018/index.php/pt2020/"]{ pointer-events: none !important; } :lang(fr) > [href="http://moldetefa.com/wp2018/index.php/m_qren/"]{ pointer-events: none !important; } html:lang(fr) a.deactivate-modal{ pointer-events: none; } html[lang="fr"] a.deactivate-modal{ pointer-events: none; }) Works on all major browsers but in iE or Edge user still see pointer events and are able to follow the link. – JohnnyF Oct 03 '18 at 07:38
  • But its working - http://joxi.ru/52agW89C4dYj7r, links are deactivated ! Problably you have very old version of IE, because IE8 and greater support the :lang selector. What you can try is to use jquery to deactivate the links I'll edit my answer now – Angel Deykov Oct 03 '18 at 08:26
  • I can confirm that link are not active on my IE, maybe from the very beginning they were deactivated, but the issue was older IE version. With the jQuery you'll avoid this. – Angel Deykov Oct 03 '18 at 08:34
  • Have you tried edge? I'm using Microsoft Edge 42.17134.1.0 and the links are activated, the modal class also activated and pointer events also. :( Can you help me with jQuery? – JohnnyF Oct 03 '18 at 08:36
  • Just confirmed, in iE 11 it works, but edge don't. Sorry my mistake – JohnnyF Oct 03 '18 at 08:46