September 10, 2024

How To Add a Custom Call-to-Action Button Using Shopify Liquid

Arrow pointing left
back to blog
Custom 'Add to Cart' Button

about

Learn how to add custom call-to-action buttons to your Shopify store using Shopify Liquid and the Shogun visual editor.

the author

Adam Ritchie
Ecommerce Contributor

share this post

While there are many factors that go into designing a Shopify page, there’s one element that very well may be more important than all the rest — the call-to-action (CTA) button.

Indeed, the whole point of the page is to persuade visitors to take a certain action, such as signing up for your newsletter or adding an item to their cart. All the effort it takes to write compelling copy, produce high-quality product photography, gather glowing customer reviews, etc. will be wasted if visitors can’t quickly figure out how to take the next step. 

This is why you must make sure that your CTA button is highly noticeable. In this guide, we’ll show you how to go beyond the standard editing options available in your Shopify theme and add a custom call-to-action button using Shopify Liquid or Shogun.

Optimize your CTAs with ShogunShogun’s visual editor offers a wide variety of advanced editing and testing features to optimize your pages on Shopify.Get started now

3 Ways to Add a Custom Call-to-Action Button on Shopify

You have a few different options for adding a custom call-to-action button to your Shopify store: you can use Shopify Liquid, Shogun’s Custom Elements feature, or the button element in Shogun’s visual editor.

Method #1: Using Shopify Liquid

Liquid is the open-source templating language that’s used to build Shopify themes. To demonstrate how Liquid works, we’ll go through the steps of using it to create an animated CTA button below. 

As mentioned above, it’s important for your CTA buttons to stand out. An animation effect will really help grab the visitor’s attention, potentially leading to more conversions and sales. 

Most themes don’t have a default option for animated CTA buttons, though — thankfully, Shopify Liquid gives you the flexibility to add just about anything you want to your store, including animation. 

To access the Liquid code for your theme, simply follow these steps:

  • After logging into your Shopify account, click on the sales channel you would like to customize in the left sidebar of the main Shopify dashboard. 
  • Open the “…” menu next to your theme. 
  • Select “Edit code”. 
You can access your theme code through the Shopify dashboard.

In the left sidebar of the code editor, open the “sections” folder and select “Add a new section”. 

In this new file, insert the following code:

<div class="section-cta">
  <a href="{{ section.settings.link }}" class="btn-animated">
  <div class="btn-content">{{ section.settings.linktext }}</div></a>
</div>


{% schema %}
{
  "name": "Call to action",
  "settings": [
  {
    "id": "link",
    "type": "url",
    "label": "Button link"
  },
  {
    "id": "linktext",
    "type": "text",
    "label": "Button text",
    "default": "Click Here"
  }
]
}
{% endschema %}

{% stylesheet %}
{% endstylesheet %}

{% javascript %}
{% endjavascript %}

The Liquid/HTML code here essentially acts as the structure for your CTA button and link. You’ll now need to add the styling and animation for your button with CSS code. 

In the left sidebar of the code editor, open the “assets” folder and select “base.css” (alternatively, you could use the search bar in the left sidebar to find this file). Then, add the following code to “base.css”:

/*=============== Animated CTA ===============*/

.section-cta {
  text-align: center;
}

.btn-animated {
  width: 200px;
  height: 50px;
  display: inline-block;
  position: relative;
  background-color: #5C6AC4;
  border-radius: 50px;
  overflow: hidden;
  cursor: pointer;
  text-align: center;
  z-index: 1;
    	
  &:before {
    content: &quot;&quot;;
    position: absolute;
    width: 140%;
    height: 100%;
    background-color: #FFFFFF;
    transform: rotate(10deg);
    top: -150%;
    left: 20%;
    transition: .3s ease-in-out;
       
  }
	
  &:after {
    content: &quot;&quot;;
    position: absolute;
    width: 140%;
    height: 120%;
    background-color: #FFFFFF;
    transform: rotate(10deg);
    top: 150%;
    left: -20%;
    transition: .3s ease-in-out;
        
  }
	
  &:hover {
    background-color: #FFFFFF;
    transition: 0s linear;
    transition-delay: .3s;
  }
	
    &:hover:before {
      top: -20px;
      left: -20%;
      transition: .3s ease-in-out;
       
   }
	
     &:hover:after {
       top: 10px;
       left: -23%;
       transition: .3s ease-in-out;
        
   }
	
     &:hover > .btn-content {
        color: #000000;
	transition: .3s ease-in-out;
   }
	
     .btn-content {
       width: 100%;
       height: 100%;
       text-align: center;
       line-height: 50px;
       color: #FFFFFF;
       font-weight: 400;
       position: relative;
       z-index: 999;
       transition: .3s ease-in-out;
  }
}

a:hover {
  opacity: 1;
}

This will add a shutter animation that’s triggered whenever a visitor hovers their mouse over the CTA button. 

Make sure to save your changes to the new Shopify section for your CTA button as well as your edits to “base.css” before moving forward.

Save the changes you’ve made to your theme code.

You’ll find that your new CTA section is now available in the Shopify Theme Editor:

  • As with editing your theme code, the first step in this process is clicking on the sales channel you want to customize in the left sidebar of the main Shopify dashboard. 
  • But instead of opening the “…” menu, click on the “Customize” button next to it.
  • Use the dropdown menu located near the top of your screen to select the page template you would like to customize. 
  • In the left sidebar of the theme editor, select “Add section”. 
  • Look for the CTA button section you just created and add it to the page. 
Your new CTA button section will now be available in the Shopify Theme Editor.

Method #2: Using Shogun Custom Elements

Shogun’s visual editor makes it especially easy to design pages for your Shopify store. 

Within the visual editor, there is an element library that contains dozens of pre-made features that you can quickly add to any page.

If you can’t find exactly what you’re looking for in the element library, you can always use Shogun’s Custom Elements feature to add it yourself:

  • After downloading and installing Shogun, select the “Apps” option in the left sidebar of the main Shopify dashboard.
  • Open Shogun.
  • Select the “Developer tools” option in the left sidebar of the main Shogun dashboard.
  • Click on the “Create new…” button. 
  • You can add Liquid/HTML, CSS, and JavaScript code for your Custom Element. 
You can create Custom Elements in Shogun using Liquid/HTML, CSS, and JavaScript.

For example, the following code adds an animated button that presses down when clicked (you would just need to swap out the default text “LINK” for the actual link and “LABEL” for the actual label you want to use):

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.button {
  padding: 15px 25px;
  font-size: 24px;
  text-align: center;
  cursor: pointer;
  outline: none;
  color: #fff;
  background-color: #04AA6D;
  border: none;
  border-radius: 15px;
  box-shadow: 0 9px #999;
}

.button:hover {background-color: #3e8e41}

.button:active {
  background-color: #3e8e41;
  box-shadow: 0 5px #666;
  transform: translateY(4px);
}
</style>
</head>
<body>

<a href="LINK">
<button class="button">TEXT</button>
</a>

</body>
</html>

Once you’ve saved your Custom Element, you’ll then be able to find it in the visual editor:

  • Select the “Pages” option in the left sidebar of the Shogun dashboard. 
  • Select the page you want to customize — this will open up the page in Shogun’s visual editor.
  • In the left sidebar of the visual editor, select the “Elements” option — this will open up the element library. 
  • Scroll down to the “Custom” section of the element library. Here, you’ll find the custom-coded CTA button you just created, which you can click and hold to place anywhere you want on the page.
Custom Elements can be accessed through the element library.

Method #3: Using the Shogun Button Element

Finally, if you’d rather not mess with any code at all, you could just use the “Button” element that’s available in the Shogun visual editor for your CTA button:

  • Open the page (or import the page from your theme) that you want to customize in Shogun’s visual editor. 
  • Open the element library.
  • Click and hold on the “Button” element, then place it on the page. 
There’s also a pre-made button element available in the element library.

As with every other element, there are myriad options for customizing your buttons in Shogun — there’s even a setting for adding pre-made animations to your button. 

You can have these animations triggered by the visitor scrolling into view of the button or hovering their mouse over the button, and your animation options include fade in, zoom in, bounce, flash, head shake, swing, and much more. And there are also customization options for many other aspects of your CTA button, including size, font, text color, background color, border style, etc. 

Shogun offers a wide variety of animation options for your CTA button.

In other words, Shogun gives you the ability to add a fully customized, animated call-to-action button to any of your Shopify pages with minimal effort and only about a minute of your time. 

Optimize your CTAs with ShogunShogun’s visual editor offers a wide variety of advanced editing and testing features to optimize your pages on Shopify.Get started now

You might also enjoy

Get started for free

Get hands on with everything you need to grow your business with a comprehensive suite of tools.
Start now
Arrow pointing up and to the right Arrow pointing up and to the right