Jump to content

Last link button in header

Recommended Posts

Site URL: https://www.ahenriksen.com

Hi,

 

I am using the bergen template on a business plan. I have made the page multilingual (english and danish), and originally the template has a button as link in the header. Though being multilingual it says the wording is english and leads to the english contact page on both language versions. I would like it to be in Danish and lead to the danish contact page when on the Danish version of the site.

 

Any suggestions?

Thank you in advance.

Link to comment
  • Replies 14
  • Views 1.1k
  • Created
  • Last Reply

You can add some custom JS in the footer. Just update the values of the newLinkPath and newLinkText variables with what you need. 

<script>
  (function(){
    var newLinkPath = '/dk/contact';
    var newLinkText = 'EXAMPLE';

    // The following code below will update url and the text of the CTA link.
    var contactLink = document.querySelector('.header-actions-action--cta a');
    var pathIsDeutsch = location.pathname.indexOf('/dk/') !== -1;
    if(contactLink && pathIsDeutsch){
      contactLink.setAttribute('href', newLinkPath);
      contactLink.textContent = newLinkText;
    }
  })();
</script>

 

Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee!

Link to comment

Hi again,

 

I a using google chrome, and inserted the following into the footer:

<script>
  (function(){
    var newLinkPath = '/dk/kontakt';
    var newLinkText = 'Kontakt';

    // The following code below will update url and the text of the CTA link.
    var contactLink = document.querySelector('.header-actions-action--cta a');
    var pathIsDanish = location.pathname.indexOf('/dk/') !== -1;
    if(contactLink && pathIsDanish){
      contactLink.setAttribute('href', newLinkPath);
      contactLink.textContent = newLinkText;
    }
  })();
</script>

Link to comment
2 hours ago, DanielHenriksen said:

Hi again,

 

I a using google chrome, and inserted the following into the footer:

<script>
  (function(){
    var newLinkPath = '/dk/kontakt';
    var newLinkText = 'Kontakt';

    // The following code below will update url and the text of the CTA link.
    var contactLink = document.querySelector('.header-actions-action--cta a');
    var pathIsDanish = location.pathname.indexOf('/dk/') !== -1;
    if(contactLink && pathIsDanish){
      contactLink.setAttribute('href', newLinkPath);
      contactLink.textContent = newLinkText;
    }
  })();
</script>

You missing a closing script tag for old code

It should be

</script>

<script>
  (function(){
    var newLinkPath = '/dk/kontakt';
    var newLinkText = 'Kontakt';

    // The following code below will update url and the text of the CTA link.
    var contactLink = document.querySelector('.header-actions-action--cta a');
    var pathIsDanish = location.pathname.indexOf('/dk/') !== -1;
    if(contactLink && pathIsDanish){
      contactLink.setAttribute('href', newLinkPath);
      contactLink.textContent = newLinkText;
    }
  })();
</script>

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

Yeah looking at your code, it looks like you may have nested the <script> tag in another <script> tag. Make sure it's outside of the other script tag or you can just place the function in an already existing script tag and forgo the script tags I wrapped in the initial code I provided. 

 

Screenshot_5_29_20__11_53_AM.png

Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee!

Link to comment
  • 2 months later...
11 hours ago, AlbaMarro said:

Hello, 

 

I had the same issue and This was very useful for me. The problem is that I can´t manage to get the right link for the button of the secondary language. How do I change that?

 

Thank you very much!

Can you share site url? We can help easier.

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
On 8/27/2020 at 1:09 AM, AlbaMarro said:

estamostrabajando

 

I'm not familiar with the jQuery code you used to create multi language site.

You can use this code to change button link on each page, it's quite manual, you will insert all the pages that you want to change link.

Add to Page Settings > Advanced > Header

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
	$('.header-actions-action a').attr('href','https://beaverhero.com');
});
</script>

replace beaverhero with new url

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.