Jump to content

Change Button Link in Header for one specific page

Go to solution Solved by Beyondspace,

Recommended Posts

  • Solution
15 hours ago, TrademarkTours said:

Site URL: https://www.trademarktours.com/hmc

On our site we use the button in the header to send people to a booking page. For this one specific page on my site, I want that button to take them to a different booking page. Can I accomplish this with a header injection code? (So far I've only succeeded in adding an extra design-less button rather than changing the existing button) 

Try adding to Home > Settings > Advanced > Code injection, footer

<script>
  (function() {
    document.addEventListener('DOMContentLoaded',() => {
      document.querySelector('#collection-619679f0e67cea457538c10c .header-actions--right .header-actions-action--cta a').setAttribute('href','/home');
    })
  })()
</script>

Change the '/home' with the slug/url you want to redirect

Let me know how it works on your site

Press 👍 or mark this answer as solution to help another one too

Greeting, it's BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Lightbox Studio plugin
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment

You can use the chrorme exxtension: Squarespace ID Finder

Here is how to find the page id: http://recordit.co/qwnj09oNCa

Hope that it can help you

Edited by bangank36

Greeting, it's BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Lightbox Studio plugin
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment
  • 1 month later...

@ekspohz Try this adjusted code

<script>
 (function() {
    document.addEventListener('DOMContentLoaded',() => {
      document.querySelector('#collection-61d9dcf755b23e793054204b .Header-nav--secondary a').setAttribute('href','/home');
    })
  })()
</script>

 

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

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment
  • 1 year later...
On 3/1/2023 at 11:27 PM, nathan.j.p said:

Is there a way to change the text of the button as well as the href  link location?

Header button or? All pages or which page?

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

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment
  • 2 weeks later...
On 3/5/2023 at 6:00 PM, tuanphan said:

Header button or? All pages or which page?

The header button on each service page.

For example:
On service page 1 I want the header button to say "Book Service 1" and link to the next step in the booking process for that service.
On  service page 2 I want the header button to say "Book Service 2" and link to the next step in the booking process for that service.

So I just need to know how to target and change the header button text, and the header button href link location per page. 

I'm assuming I'll have to use some javascript in settings>advanced>code injection which I know how to do. I just don't know how to target the header button specifically.

Thank you @tuanphan

Link to comment
On 3/15/2023 at 3:24 AM, nathan.j.p said:

The header button on each service page.

For example:
On service page 1 I want the header button to say "Book Service 1" and link to the next step in the booking process for that service.
On  service page 2 I want the header button to say "Book Service 2" and link to the next step in the booking process for that service.

So I just need to know how to target and change the header button text, and the header button href link location per page. 

I'm assuming I'll have to use some javascript in settings>advanced>code injection which I know how to do. I just don't know how to target the header button specifically.

Thank you @tuanphan

Hi,

Yes. This is possible. Can you share link to a service page? We can check & give code easier

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

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment
On 3/18/2023 at 10:20 PM, nathan.j.p said:

Sure, we just have basic service pages set up for now. You can go to Mothershipfitness.com. Thanks @tuanphan

Add to Page Header

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
   $("header#header a.btn").html(function() { 
          return $(this).html().replace("Start training for free", "new text");  
    });
$("header#header a.btn").attr('href','https://google.com');
});
</script>

 

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

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment
2 hours ago, tuanphan said:

Add to Page Header

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
   $("header#header a.btn").html(function() { 
          return $(this).html().replace("Start training for free", "new text");  
    });
$("header#header a.btn").attr('href','https://google.com');
});
</script>

 

@tuanphan This is awesome! Works perfectly.

Link to comment

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.