Additional menu button plugin

Additional menu button plugin

Add an additional button to Squarespace menu on desktop & mobile

Shape SquareSpace 7.1
Requires Business plan or higher
Free

Why use

By default, Squarespace allows only one button in the header, but sometimes you want more.

Code

<!-- Additional Menu Button plugin by opsquare.co --> 

<!-- JS --> 
<script>  
(function () {

    /*** Plugin options ***/
    const options = {
        text: 'Button text',
        url: 'https://google.com',
        type: 'secondary',  // primary / secondary / tertiary
        position: 'before', // before / after
        newTab: true,
        showOnMobile: true
    };
    /*** Stop editing ***/

    function opAdditionalButton() {
        const buttonClass = options.type
            ? `sqs-button-element--${options.type.toLowerCase()}`
            : 'sqs-button-element--primary';
        const targetAttr = options.newTab ? 'target="_blank"' : '';

        const buttonHTML = `<a class="btn btn--border theme-btn--primary-inverse 
                            op-added-button op-added-button--desktop 
                            ${buttonClass}" ${targetAttr} href="${options.url}">
                                ${options.text}
                            </a>`;

        const constMobileButtonHTML = `<a class="theme-btn--primary btn ${buttonClass} op-added-button op-added-button--mobile" ${targetAttr} href="${options.url}">
  ${options.text}
</a>`;

        document.body.classList.add('op-has-desktop-nav-menu-button');

        // Desktop insertion
        const desktopTarget = document.querySelector('.header-display-desktop .header-actions-action--cta');
        if (desktopTarget) {
            desktopTarget.insertAdjacentHTML(
                options.position === 'after' ? 'beforeend' : 'afterbegin',
                buttonHTML
            );
        }

        // Mobile insertion
        if (options.showOnMobile) {
            const mobileTarget = document.querySelector('.header-menu-cta');
            mobileTarget.classList.add('header-menu-cta--additional-btn');
            if (mobileTarget) {
                mobileTarget.insertAdjacentHTML(
                    options.position === 'after' ? 'beforeend' : 'afterbegin',
                    constMobileButtonHTML
                );
            }
        }
    }

    document.addEventListener('DOMContentLoaded', e => {
       opAdditionalButton();
    });
})();
</script>

<style>
:root {
  --op-additional-button-margin: 8px;
}
  
.header-actions-action--cta a + a {
  margin-left: var(--op-additional-button-margin) !important;
}
</style>

<!-- end Additional Menu Button plugin -->

How to install

  1. Add code to Code Injection
  2. Set up the options

Options

Javascript

/*** Plugin options ***/

const options = {
    text: 'TEXT',
    url: 'LINK',
    type: 'secondary',  // primary / secondary / primary
    position: 'before', // before / after
    newTab: true,
    showOnMobile: true
};

/*** Stop editing ***/
Option Value Description Example
text Any text The text that will appear on the button Log in
url Full link starting with https:// The URL the button will link to https://google.com
type primary | secondary | tetriary The button type primary
position before | after Displays the button before or after the default one before
newTab true | false Open the link in a new tab true
showOnMobile true | false Display the button in the mobile navigation true

CSS Variables

--op-additional-button-margin: 4px; /* Distance between the buttons */