Jump to content

Remove a link from Multilanguage website

Recommended Posts

Site URL: http://wolu.cl

Hello community!

I'm trying to remove a link from secondary navigation in English version of my website 'www.wolu.cl' . I was following a code and after many tries it isn't working even is the class is added when i check in inspector. Do you have any advices to solve it?  Thank you!

- "Tienda"  is for Spanish store and is an external link to 'https://www.wolueditorial.cl/'
- "Store" is for English store and it will be a Squarespace page to 'http://wolu.cl/en/store'

image.thumb.png.a7de3f08ce2f110c9149ddb971dd414a.png

 

I'm using Brine and here is the code:

/* ACTIVE LINKS */
    if (lang == "en") {
          $('a[href="/"]').attr("href","/en/home");
        $('.Header-nav--secondary a:nth-child(1)').addClass('remove');
    }
    if (lang == "es") {
          $('a[href="/"]').attr("href","/es/inicio");
        $('.Header-nav--secondary a:nth-child(2)').addClass('remove');
    }

And the complete code:

<script>
        $(function() {
    /* SETUP MULTI-LANGUAGE */
    var defaultLanguage = 'es';
    var lang = location.pathname.split("/")[1];
    var defaultClass = 'lang-'+defaultLanguage+'';
    var itemParent = "nav [class*='collection'],nav [class*='folder'],nav [class*='index'],nav [class*='group']";
    if (lang == "" || lang.length > 2 ){
      var lang = defaultLanguage;
    }

    /* ADD LANGUAGE CLASSES */
        $('a[href="/"]').addClass('lang-'+defaultLanguage+'').parents(itemParent).addClass('lang-'+defaultLanguage+'');
        $('nav a:link:not([href^="http://"]):not([href^="https://"])').each(function () {
      var langType = $(this).attr('href').split("/")[1];
      var multiLanguageClass = 'multilanguage lang-' + langType + '';
      if (undefined !== langType && langType.length <= 2) 
                                    $(this).addClass(multiLanguageClass).parents(itemParent).addClass(multiLanguageClass);
    });
           $('nav button').each(function () {
      var langTypeFolder = $(this).attr('data-controller-folder-toggle').split("/")[0];
      var multiLanguageClass = 'multilanguage lang-' + langTypeFolder + '';
      if (undefined !== langTypeFolder && langTypeFolder.length <= 2) 
        $(this).addClass(multiLanguageClass);
    });

      
    /* ADD EXCLUSION NAV ITEMS */
        $('.exclude-me,.exclude-me a').addClass('exclude');
        $('.sqs-svg-icon--list a,.SocialLinks-link').addClass('exclude');

    /* REMOVE OTHER LANGUAGES AND KEEP EXCLUDED ITEMS */
        $('.multilanguage:not(".lang-'+lang+',.exclude")').remove();
      
    /* ACTIVE LINKS */
    if (lang == "en") {
          $('a[href="/"]').attr("href","/en/home");
        $('.Header-nav--secondary a:nth-child(1)').addClass('remove');
    }
    if (lang == "es") {
          $('a[href="/"]').attr("href","/es/inicio");
        $('.Header-nav--secondary a:nth-child(2)').addClass('remove');
    }

    /*setup language switcher*/
        $('body').prepend('<div class="language"><a href="http://wolu.cl/en/home" class="lang-en">EN</a> | <a href="http://wolu.cl/es/inicio" class="lang-es">ES</a></div>');

    /* NOT REQUIRED */
    /* SETUP URL REROUTE FOR MATCHING LANGUAGE PAGE */
    switch (window.location.pathname) {
      case '/en/contact':
        $(".language a.lang-en").attr("href", "/en/contact");
        $(".language a.lang-es").attr("href", "/es/contacto");
        break;
      case '/es/contacto':
        $(".language a.lang-en").attr("href", "/en/contact");
        $(".language a.lang-es").attr("href", "/es/contacto");
        break;
                                    }
  });
  
</script>

 

Link to comment
  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.