Hello! I do a task on WP, the site is multilingual, social networks icons should be displayed on each page, in 2 versions:

1) all social networks (in Russian)

<script type="text/javascript">(function() { if (window.pluso)if (typeof window.pluso.start == "function") return; if (window.ifpluso==undefined) { window.ifpluso = 1; var d = document, s = d.createElement('script'), g = 'getElementsByTagName'; s.type = 'text/javascript'; s.charset='UTF-8'; s.async = true; s.src = ('https:' == window.location.protocol ? 'https' : 'http') + '://share.pluso.ru/pluso-like.js'; var h=d[g]('body')[0]; h.appendChild(s); }})();</script><div class="pluso" data-background="transparent" data-options="small,square,line,horizontal,nocounter,theme=08" data-services="vkontakte,odnoklassniki,facebook,twitter,google"></div>' 

2) all social networks without VK and Odnoklassniki (in English)

 <script type="text/javascript">(function() { if (window.pluso)if (typeof window.pluso.start == "function") return; if (window.ifpluso==undefined) { window.ifpluso = 1; var d = document, s = d.createElement('script'), g = 'getElementsByTagName'; s.type = 'text/javascript'; s.charset='UTF-8'; s.async = true; s.src = ('https:' == window.location.protocol ? 'https' : 'http') + '://share.pluso.ru/pluso-like.js'; var h=d[g]('body')[0]; h.appendChild(s); }})();</script><div class="pluso" data-background="transparent" data-options="small,square,line,horizontal,nocounter,theme=08" data-services="facebook,linkedin,twitter,google"></div> 

Tell me how it can be done on jQuery with the condition that will work on the URL in which there is en and ru?

    1 answer 1

    Understood!
    I give the code in two versions, because jQuery was not and so that there were no conflicts not connected, the code itself (jQuery (comment) and pure JS):

     // $(document).ready(function() { var str = window.location.href; if (str.indexOf('/ru/') != -1) { var russ = document.querySelector("#rus"); russ.setAttribute('style','visibility: visible'); }; if (str.indexOf('/en/') != -1) { var enn = document.querySelector("#en"); enn.setAttribute('style','visibility: visible'); }; if (str.indexOf('/es/') != -1) { var ess = document.querySelector("#es"); ess.setAttribute('style','visibility: visible'); }; if (str.indexOf('/ru/') != -1) { // $("#rus").css('visibility', 'visible'); // $("#en").css(['visibility', "hidden"]); // $("#es").css(['visibility', "hidden"]); // console.log(333); // // if (str.indexOf('/en/') != -1) { // // $("#rus").css('display', "hidden"); // $("#en").css('display', "visible"); // $("#es").css('display', "hidden"); // // if (str.indexOf('/es/') != -1) { // // $("#rus").css('display', "hidden"); // $("#en").css('display', "hidden"); // $("#es").css('display', "visible"); // }; // } 
    • not a good solution, if all three are in the url, and anywhere in the url, then all three blocks will be visible - Grundy
    • The @Grundy site is simple, so it is suitable for the current task, if there are other options, write, I’ll be happy to see the alternative. - ultimatum
    • but I didn't see the usual indexOf, then it's ok - Grundy
    • @Grundy Thank you! I'm just learning!) - ultimatum