Jump to content

Modifying the Header Button's text and action, when on mobile

Go to solution Solved by tuanphan,

Recommended Posts

Is there a way to modify the header button to display different text and perform a different action when clicked, depending on whether the user is on mobile vs not on mobile? On mobile, I would like the text of the header button to read "Call Now" and perform a "Phone" action when clicked. When not on mobile, I would like the text of the header button to read "Contact Us" and perform a "Page" action when clicked, and to bring the user to the "contact" page. I currently have some code that effects the header button, which may or may not be relevant:


 

/* Show button on mobile menu*/
@media screen and (max-width:1024px) {
    .header-actions-action--cta a {
        border-radius:5px;
        padding: .8em .8em !important
    }

    .header-actions {
        display: block !important
    }

    .header .header-actions-action--cta {
        display: block;
        width: 0% !important;
        padding-right: 0px;
        padding-left: 0px
    }

    .header-title-nav-wrapper {
        flex: 100% !important;
        padding-right: 0px;
        padding-left: 0px
    }
}

 

Thank you

Link to comment
  • Replies 4
  • Views 277
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution
On 5/24/2023 at 2:29 AM, JoshB said:

Add this to Settings > Advanced > Code Injection > Footer

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<script>
  jQuery(document).ready(function($){
    if ($(window).width() > 992) {
  $('div.header-actions-action a.btn').attr('href','/contact');
        $("div.header-actions-action a.btn").html(function() { 
          return $(this).html().replace("Call Now: (470)TRAIN-ME", "Contact Us");  
    });
    }
})
</script>

image.thumb.png.faca118db380faede8981971fef7ffed.png

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

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.