Adding embed code

After you create a Buy Button in your Shopify admin, you're ready to add it to your own website or blog.

The process of adding embed code to your website's source HTML is a bit different depending on how and where you want your Buy Buttons and cart to appear, on your publishing platform, and sometimes on the theme you're using on that platform.

Platform-specific walkthroughs

You can sell your products on WordPress, Squarespace, and Tumblr, on your own website, or wherever you've already built an audience online:

Advanced integrations

Tip

If you need help with adding embed code to publishing platforms outside of Shopify (such as Tumblr, Squarespace, WordPress.org blogs), then contact your website provider or publishing platform directly for support.

Adding embed code to a WordPress.org blog

You can add embed code to individual posts and to the menu on the homepage of your WordPress.org blog.

Tip

Embedded Buy Buttons are compatible with the WordPress.org platform — but not with WordPress.com. This documentation describes WordPress 4.2.2. Your version might be different. Learn more ›

Add embed code to a post

To add embed code to an individual post:

  1. In Shopify, create a Buy Button and copy its embed code from the Embed Code dialog (or click Copy embed code to clipboard):
    Generate cart embed code
  2. From your WordPress Dashboard, click Posts:
    Wp posts
  3. Click Add New to create a new post, or click the name of an existing post that you want to display a Buy Button.
  4. From the Add New Post or Edit Post page, change the text editor from Visual to Text mode:
    Wordpress editor
  5. Paste the embed code into the editor's main text field in the place where you want the Buy Button or collection to appear:
    Wordpress editor embed
  6. When you're done, click Save Draft, Preview, or Publish.

Add embed code to a menu

To add embed code to a menu on the homepage:

  1. From your WordPress dashboard, click Appearance:
    Wordpress appearance
  2. Click Customize to open the theme editor, and then click Widgets:
    Wordpress customize
  3. Click the name of the area where you want to add the Buy Button or custom cart code:
    Wordpress sidebar
  4. Open an existing Text widget, or click Add a Widget, and then click Text:
    Wordpress choose widget
  5. Paste the embed code into the main text field within the Text widget:
    Buy button wordpress widget
  6. Save your changes.

Tip

If you want to change the behavior or appearance of your website's cart, you can add custom cart code to a menu on the homepage of your WordPress.org blog.

Adding embed code to your Shopify blog

You can add embed code to individual posts on your Shopify blog:

  1. From your Shopify admin, click Online Store.
  2. Click Blog Posts.
  3. From the Blog Posts page, click the title of a blog post you want to edit, or click Add blog post to create a new one:
    Shopify add blog
  4. In the Write your blog post section, click Show HTML in the rich text editor:
    Shopify rte html
  5. Paste your embed code into the main text field:
    Shopify add embed
  6. Click Save.

Adding embed code to Squarespace

Caution

Some advanced customizations on Squarespace are theme-specific. These customizations aren't supported by Shopify — use them at your own risk!

You can add embed code to individual posts in Squarespace and to the menus on your homepage. In some cases, you might want to do both. For example, you can embed a cart on your homepage to receive purchases from Buy Buttons that you embed on individual posts.

To add embed code to page elements in Squarespace:

  1. From your Squarespace dashboard, open the webpage where you want to add the embed code.

  2. Find the element on the page where you want the Buy Button or embedded cart to appear, hover over the Page Content area, and then click EDIT:

    Squarespace edit page

  3. Click the insert point where you want to add the embed code:

    Squarespace insert point

  4. In the More section of the Content Blocks dialog, click Code:

    Squarespace code block

  5. From your Shopify admin, copy the embed code from the Embed Code dialog:

    Buy button embed code

  6. From your Squarespace dashboard, paste the embed code into the CODE dialog:

    Squarespace paste code
    Make sure that the text field is set to receive HTML.

  7. Click APPLY on the EDIT CODE dialog.

  8. Click SAVE again on the page editor:

    Squarespace save page
    Since Squarespace disables JavaScript in its dashboard, you need to preview your page separately to see the Buy Button or embedded cart that you've added.

Tip

If you add an embedded cart to a menu on your Squarespace homepage, it will receive orders from Buy Buttons that you embed on individual posts.

Adding embed code to Tumblr

Caution

Since Tumblr disables JavaScript on its dashboard, Buy Buttons won't appear in your dashboard preview. You can click Preview on blog to see your Buy Buttons instead of using the dashboard preview.

You can add embed code to individual posts in Tumblr and to the menu on your homepage

Add embed code to a post in Tumblr

To add embed code to an individual post:

  1. From your Tumblr dashboard, create a new Text post.
  2. Click the Gear icon, then click the Text Editor dropdown and select HTML:
    Buy button tumblr gear
  3. Paste your embed code into the Tumblr editor:
    Buy button tumblr editor
  4. Click Post.

Add embed code to a page header in Tumblr

To add embed code to the header on your Tumblr homepage:

  1. From your Tumblr dashboard, open the account menu, and then click Edit appearance:
    Buy button tumblr account menu
  2. Click Edit Theme.
  3. Click Edit HTML:
    Buy button tumblr edit html
  4. In the Edit HTML area, find the end of the header element in the source HTML:
    Buy button tumblr header
  5. Paste your embed code above the </header> tag:
    Buy button tumblr embed
  6. Save your changes.

Adding embed code to Wix

After you've created a Buy Button or collection in your Shopify admin, you can add it to your Wix website using the Wix Website Editor.

Caution

If you want to embed Buy Buttons for multiple products or collections, then you need to edit the embed code before adding it to the Wix HTML code widget. If you embed more than one Buy Button into your Wix website without editing the embed code, then customers trying to buy more than one product will see a separate cart for each product.

If you want to display more than one product on your Wix website without editing the embed code, then you can embed a collection. You can create a new collection in your Shopify admin for the products that you want to display on Wix.

To embed a single Buy Button for a product or collection on your Wix website:

  1. From your Shopify admin, create a Buy Button for a product or collection, and then copy its embed code.
  2. From your Wix account, find the site you want to edit in the My Sites section, and then click Edit Site:
    Wix edit site
  3. In the Wix Website Editor, click the + button, and then click More:
    Wix add menu
  4. Click HTML Code to add an HTML code widget to the page:
    Wix html widget
  5. Click Enter Code.
  6. On the HTML Settings dialog, paste the embed code for your Buy Button or collection in the Add your code here field and then click Update:
    Wix add code
  7. Resize the HTML code widget to fit its contents. If you are creating an embed with a cart, make sure the cart tab appears in the right place.
  8. When you're done, click Save.

Embed multiple products or collections

To embed multiple products or collections on your Wix website:

  1. From your Shopify admin, create a Buy Button for a product or collection, and then copy its embed code.
  2. Paste the code into a code editor or the Wix website builder. Repeat the first two steps until you have created the Buy Buttons you need.
  3. Edit the embed codes to make sure they will display in the proper alignment.
  4. From your Wix account, find the site you want to edit in the My Sites section, and then click Edit Site:
    Wix edit site
  5. In the Wix Website Editor, click the + button, and then click More:
    Wix add menu
  6. Click HTML Code to add an HTML code widget to the page:
    Wix html widget
  7. Click Enter Code.
  8. On the HTML Settings dialog, paste the edited code for your Buy Buttons in the Add your code here field and then click Update:
    Wix add code
  9. Resize the HTML code widget to fit its contents. If you are creating an embed with a cart, make sure the cart tab appears in the right place.
  10. When you're done, click Save.

    Note

    Need help using the Wix Editor? Contact Wix Support.

Add script tags separately

Some platforms (like Unbounce) require that you paste the embed code's <script> tags in the page header, and the rest of the embed code on the page where you want the Buy Button to appear.

To add script tags separately:

  1. From the embed code that's generated when you create a Buy Button, copy both the <div> element and the <script> element. For example:

    <script type="text/javascript">
    /*<![CDATA[*/
    
    (function () {
      var scriptURL = 'https://sdks.shopifycdn.com/buy-button/latest/buy-button-storefront.min.js';
      if (window.ShopifyBuy) {
        if (window.ShopifyBuy.UI) {
          ShopifyBuyInit();
        } else {
          loadScript();
        }
      } else {
        loadScript();
      }
    
      function loadScript() {
        var script = document.createElement('script');
        script.async = true;
        script.src = scriptURL;
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);
        script.onload = ShopifyBuyInit;
      }
    
      function ShopifyBuyInit() {
        var client = ShopifyBuy.buildClient({
          domain: 'haris-mahmood.myshopify.com',
          apiKey: 'a4e6808b1c4afa490c5b7459f7758347',
          appId: '15',
        });
    
        ShopifyBuy.UI.onReady(client).then(function (ui) {
          ui.createComponent('product', {
            id: [9017131142],
            node: document.getElementById('product-component-2dd3c8704e6'),
            moneyFormat: '%24%24%24%7B%7Bamount%7D%7D',
            options: {
      "product": {
        "variantId": "all",
        "contents": {
          "variantTitle": false,
          "description": false,
          "buttonWithQuantity": false,
          "quantity": false
        },
        "styles": {
          "product": {
            "@media (min-width: 601px)": {
              "max-width": "calc(25% - 20px)",
              "margin-left": "20px",
              "margin-bottom": "50px"
            }
          }
        }
      },
      "cart": {
        "contents": {
          "button": true
        },
        "styles": {
          "footer": {
            "background-color": "#ffffff"
          }
        }
      },
      "modalProduct": {
        "contents": {
          "variantTitle": false,
          "buttonWithQuantity": false,
          "quantity": false
        },
        "styles": {
          "product": {
            "@media (min-width: 601px)": {
              "max-width": "100%",
              "margin-left": "0px",
              "margin-bottom": "0px"
            }
          }
        }
      },
      "productSet": {
        "styles": {
          "products": {
            "@media (min-width: 601px)": {
              "margin-left": "-20px"
            }
          }
        }
      }
    }
          });
        });
      }
    })();
    /*]]>*/
    </script>
    
  2. Open the page header for the website where you want to embed a Buy Button.

  3. Paste the entire <script> element in the page header.

  4. Save your cahnges.

  5. From the original embed code in your Shopify admin, copy only the <div> element. For example:

    <div id='product-component-2dd3c8704e6'></div>
    
  6. Open the page on your website where you want to embed a Buy Button.

  7. Paste the <div> code snippet into the page.

  8. Save your changes.

Want to discuss this page?

Visit the Shopify Community

Ready to start selling online with Shopify?

Try it free