Jump to content

Add multiple buttons to header nav in Squarespace 7.1

Go to solution Solved by tuanphan,

Recommended Posts

7 hours ago, Dsebas said:

If I decide to add more pages I guess i'll need to add those to the code as well.

Yes but I tried to make it pretty easy. For the button adding code you add to buttonsNewData. And for language translation urlFragmentTranslationData. And of course URL Mappings.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
On 9/10/2020 at 9:43 PM, creedon said:

This is for a v7.1 site and you will need to have at least the business plan to implement the following solution.

In Design > Custom CSS put the following.


/* begin add buttons to header */

  .header-actions-action.header-actions-action--cta {
  
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    
    /*
    
      default orientation is row, for column swap commented values in lines
      below
      
      */
      
    -webkit-box-orient: horizontal; /* vertical */
    -webkit-box-direction: normal;
    -ms-flex-direction: row; /* column */
    flex-direction: row; /* column */
    
    grid-gap: 0.5em;
    gap: 0.5rem;
    
    text-align: center;
    
    }
    
  /* end add buttons to header */

In Settings > Advanced > Code Injection > HEADER put the following.


<script src="//ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

The above loads the jQuery library which I find makes doing these kinds of coding tasks easier.

In Settings > Advanced > Code Injection > FOOTER put the following.


<script>

  /* add buttons to header */
  
  $( ( ) => {
  
    let buttonsNewData = [
    
      {
      
        buttonText: 'enter button text here 1',
        url: 'enter url here 1'
        
        }
      ]
    
    $( '.header-actions-action--cta, .header-menu-cta' ).each ( function ( ) {
    
      let $this = $( this );
      
      $.each ( buttonsNewData, function ( index, buttonNewData ) {
      
        $( '.btn:first', $this ).clone ( )
        
          .attr ( 'href', buttonNewData.url )
          
          .text ( buttonNewData.buttonText )
          
          .appendTo ( $this );
          
        } );
        
      } );
      
    } );
    
  </script>

The code allows for adding more than one button as we can see from the following code snippets. Here we add one.


      {
      
        buttonText: 'enter button text here 1',
        url: 'enter url here 1'
        
        }

By repeating the previous data structure we can add more buttons. Here we add two.


      {
      
        buttonText: 'enter button text here 1',
        url: 'enter url here 1'
        
        }, // notice the comma here
      {
      
        buttonText: 'enter button text here 2',
        url: 'enter url here 2'
        
        } /* notice NO comma here, the last object doesn't get one,
             if you are adding only one button (object) it doesn't get one */

And here we add three.


      {
      
        buttonText: 'enter button text here 1',
        url: 'enter url here 1'
        
        }, // notice the comma here
      {
      
        buttonText: 'enter button text here 2',
        url: 'enter url here 2'
        
        }, // notice the comma here
      {
      
        buttonText: 'enter button text here 3',
        url: 'enter url here 3'
        
        } /* notice NO comma here, the last object doesn't get one,
             if you are adding only one button (object) it doesn't get one */

Let us know how it goes.

Messaged you with a very specific question

Link to comment
  • 2 weeks later...

Thanks @creedon for the code and all the help you've provided in this thread.

I was trying it on my Squarespace 7.1 website but had to remove the code because I was having two issues with it which I couldn't solve. I am wondering if you might have any thoughts as what to tweak?

First, I was using the code to place a second button next to the default Squarespace navigation button. The positioning appeared correct on Chrome, but when viewed on Safari the two buttons were flush against each other with no padding in-between. Any way to make this consistent across browsers?

Second, I think when the coded button is next to the Squarespace 7.1 default nav button it takes on the same parameters. I.e., if I set the Squarespace button to open in a new tab then the coded one must as well. I'd like to set the Squarespace button to open in the same tab to an internal page and the coded button to open a file in a new tab. Is there any way to set the coded button to open in a new tab, where it doesn't take on the parameters of the other button to open in the same tab?

Thanks.

 

Link to comment
  • 1 month later...
8 hours ago, duckdog said:

I'm wondering if there's a way to style that second button differently than the first. Perhaps by giving it a unique class or id?

Possibly. Please post the URL to your site. That way I can figure what code you used. I made several code posts in this thread so it would help me to know which one you used.

If your site is not public please set up a site-wide password, if you've not already done so. Post the password here.

We can then take a look at your issue.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

Is it feasible to hide the Add to cart button on selected merchandise? Or all merchandise in one shop folder, but no longer all merchandise within the whole online keep?

Link to comment

@KEWALJULLE21

Your issue seems to be different to the original poster's topic. I suggest starting a new forum topic with your issue. It would also help if you could you provide URLs to specific pages with what you want to accomplish on each page.

Edited by creedon

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
  • 1 month later...

Hi. These posts have been super helpful! Thank you for that. I'm wanting to see if there's a possibility to have buttons on both sides of the header. I currently have three buttons created but they reside on the right side of the logo since that is the format of the header. 

abueshehmd.com 

Thanks in advance! 

Link to comment
On 2/26/2021 at 6:22 AM, yazfuz said:

Hi. These posts have been super helpful! Thank you for that. I'm wanting to see if there's a possibility to have buttons on both sides of the header. I currently have three buttons created but they reside on the right side of the logo since that is the format of the header. 

abueshehmd.com 

Thanks in advance! 

Hi. You need to use JavaScript to do this. Do you use Personal or Business or COmmerce Plan?

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

Dear @creedon, this code is amazing and works perfectly to create multiple buttons, thanks a lot! However, would it be possible to use a similar method to create a single button without using the "edit header > elements > button" path? I am trying to have a single button linking to different pages on each page of the website, making it a language selector for each of those individual pages.
Thanks for your help.

Link to comment
On 3/3/2021 at 7:40 AM, MiguelFerrao said:

Dear @creedon, this code is amazing and works perfectly to create multiple buttons, thanks a lot! However, would it be possible to use a similar method to create a single button without using the "edit header > elements > button" path? I am trying to have a single button linking to different pages on each page of the website, making it a language selector for each of those individual pages.
Thanks for your help.

You can add more items to navigation, then we can use custom code to turn nav links to buttons.

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
  • 2 weeks later...

Hello,

i'm having issues with one button added with this script in mobile version of the site. when i create first button with EN language, it shows all buttons in the menu. but when i switch to second language no buttons are shoeing up in mobile version. in desktop version everything is working fine

Link to comment

@pfilipek

Please post the URL for your site.

If your site is not public please set up a site-wide password, if you've not already done so.

Post the password here.

Adding a site-wide password is not a security breach. Please read the documentation at the link provided to understand how it works.

We can then take a look at your issue.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

@pfilipek

My code is not involved. By the time my code runs other code has removed the cta button so my code can not clone it.

Here is the line of code that is causing the button to be removed.

$('.multilanguage:not(".lang-'+lang+',.exclude")').remove();

 

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
  • 2 weeks later...

@Aeduuin

Turning off your custom CSS locally allows the buttons to fit properly.

511082475_ScreenShot2021-03-24at9_13_03PM.thumb.png.59b24eb0f8b4e1d67929e38baf6f7231.png

A quick view of your CSS shows that you've added some code to include a graphic. Can you rebuild that code to work better with the additional space the new button adds?

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

@Aeduuin

Here's a thought! I think you have enough vertical room to stack the buttons. Use the column value instead of row. There is a note on it in the CSS code I provided.

 

Edited by creedon

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
  • 3 weeks later...
On 9/25/2020 at 2:45 PM, tuanphan said:

Add to Home > Design > Custom CSS


a.btn[href*="give/now"] {
    background-color: green;
    border-color: green;
}

 

Hi @tuanphan

I also followed @creedon's brilliant specs to get multiple buttons on the header - thank you Creedon!
I will need the last button 'book now' to be red, please can you help with this?

I tried something like the below, but no luck:

a.btn[href*="book/now"]
{ background-color: red;
border-color: red; }


https://seadragon-purple-45ra.squarespace.com/home
PW: 97hTryfC


Thank you 🙂

Link to comment

@LXK

Try the following.

.bright-inverse .header-actions .btn[href="/contact"] {

  background-color : red;
  border-color : red;
  
  }

This is for v7.1.

Let us know how it goes.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
2 minutes ago, creedon said:

@LXK

Try the following.


.bright-inverse .header-actions .btn[href="/contact"] {

  background-color : red;
  border-color : red;
  
  }

This is for v7.1.

Let us know how it goes.

It worked! Thank you so much @creedon 😄 

Link to comment
On 4/12/2021 at 10:44 PM, LXK said:

It worked! Thank you so much @creedon 😄 

Hey @creedon,

I'm back with another questions for you.

Is it possible to remove the button's on mobile navigation and change them back to links?

Currently the buttons's are causing the mob navigation links to be super separated.

Your help is very much appreciated 😃

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.