Ad

Shopify Adding .text-link Class To Button When .btn Is Only Class Defined

- 1 answer

While customizing a Shopify page, I've added a dynamic button with the class of only

{% if section.settings.button_label != blank and section.settings.button_link != blank %}
         <a target="_blank" rel="nofollow noreferrer" href="{{ section.settings.button_link }}" class="btn">
           {{ section.settings.button_label | escape }}
         </a>
{% endif %}

However, when the page loads, it has now appended .text-link to my button classes, overriding the styling of the button.

    a.btn.text-link {
      -webkit-appearance: none;
    background-color: #2c2d36;
    background-image: none;
    border: 1px solid transparent;
    border-bottom: 1px solid #2c2d36;
    border-radius: 0;
    box-sizing: border-box;
    color: #fff;
    cursor: pointer;
    display: inline-block;
    font-family: Futura,sans-serif;
    font-size: .8125em;
    font-weight: 700;
    letter-spacing: .1em;
    line-height: 1.42;
    margin: 0;
    padding: 8px 10px;
    text-align: center;
    text-decoration: none;
    text-transform: uppercase;
    transition: background-color .4s ease-out;
    user-select: none;
    vertical-align: middle;
    white-space: normal;
    width: auto;
    }

Anyone have a sense of where I should be looking to stop this from appending to my single class?

Link: https://shop.creekretreat.com/pages

Link: https://shop.creekretreat.com/pages/services (Group of buttons on first image/text section)

Thanks in advance, much appreciated.

K

Ad

Answer

There is a JS function in your theme.js which is doing this:

theme.styleTextLinks = function() {
  $('.rte').find('a:not(:has(img))').addClass('text-link');
};

This function is called in the theme.init method:

theme.init = function() {
  theme.initCache();
  theme.setBreakpoints();
  theme.fitNav();
  theme.cartInit();
  theme.afterCartLoad();
  theme.checkoutIndicator();
  theme.returnLink();
  theme.styleTextLinks(); <----- here
  ......

You will need to update the JS to fit your needs or remove this logic all together.

Ad
source: stackoverflow.com
Ad