Adding Buy Button code to HTML
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.
On this page
Adding embed code to a WordPress.org blog
You can add embed code to individual posts and to the menu on the home page of your WordPress.org blog.
Add embed code to a WordPress post
- In Shopify, create a Buy Button and copy its embed code from the Embed Code dialog (or click Copy embed code to clipboard).
- From your WordPress dashboard, go to your posts.
- Create a new post, or edit an existing post where you want to display a Buy Button.
- Depending on the WordPress version you're using, complete one of the following steps:
- In the post, change the text editor from Visual to Text mode.
- From the block editor, click the
+
button, search forCustom HTML
, and then click Custom HTML.
- Paste the embed code into the text field in the place where you want the Buy Button or collection to appear.
- When you're done, click Save Draft, Preview, or Publish.
Add embed code to a Wordpress menu
Steps:
- From your WordPress dashboard, click Appearance.
- Click Customize to open the theme editor, and then click Widgets.
- Click the name of the area where you want to add the Buy Button or custom cart code.
- Open an existing Text widget, or click Add a Widget, and then click Text.
- Paste the embed code into the main text field within the Text widget.
- Save your changes.
Adding embed code to your Shopify blog
Steps:
- From your Shopify admin, go to Online Store > Blog Posts.
- 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.
- In the Write your blog post section, click Show HTML in the rich text editor.
- Paste your embed code into the main text field.
- Click Save.
Adding embed code to Squarespace
You can add embed code to individual posts in Squarespace and to the menus on your home page. In some cases, you might want to do both. For example, you can embed a cart on your home page to receive purchases from Buy Buttons that you embed on individual posts.
Steps:
- From your Squarespace dashboard, open the webpage where you want to add the embed code.
- Find the element on the page where you want the Buy Button or embedded cart to appear, move your cursor over the Page Content area, and then click EDIT.
- Click the insert point where you want to add the embed code.
- In the More section of the Content Blocks dialog, click Code.
- From your Shopify admin, copy the embed code from the Embed Code dialog.
- From your Squarespace dashboard, paste the embed code into the CODE dialog. Make sure that the text field is set to receive HTML.
- Click APPLY on the EDIT CODE dialog.
- Click SAVE again on the page editor. Because 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.
If you complete the steps and your Buy Button is not loading, then you might need to disable Ajax loading. To see more details, go to Enable or disable Ajax.
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.
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.
Steps:
- From your Shopify admin, create a Buy Button for a product or collection, and then copy its embed code.
- From your Wix account, find the site you want to edit in the My Sites section, and then click Edit Site.
- In the Wix Website Editor, click the
+
button, and then click More. - Click HTML Code to add an HTML code widget to the page.
- Click Enter Code.
- 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.
- Resize the HTML code widget to fit its contents. If you are creating an embed with a cart, then make sure the cart tab appears in the right place.
- When you're done, click Save.
Embed multiple products or collections
Steps:
- From your Shopify admin, create a Buy Button for a product or collection, and then copy its embed code.
- 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.
- Edit the embed codes to make sure they display in the proper alignment.
- From your Wix account, find the site you want to edit in the My Sites section, and then click Edit Site.
- In the Wix Website Editor, click the
+
button, and then click More. - Click HTML Code to add an HTML code widget to the page.
- Click Enter Code.
- On the HTML Settings dialog, paste the edited code for your Buy Buttons in the Add your code here field and then click Update.
- Resize the HTML code widget to fit its contents. If you are creating an embed with a cart, then make sure the cart tab appears in the right place.
- When you're done, click Save.
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.
Steps:
-
From the embed code that's generated when you create a Buy Button, copy both the
<div>
element and the<script>
element. For example: -
Open the page header for the website where you want to embed a Buy Button.
-
Paste the entire
<script>
element in the page header. -
Save your changes.
-
From the original embed code in your Shopify admin, copy only the
<div>
element. For example: -
Open the page on your website where you want to embed a Buy Button.
-
Paste the
<div>
code snippet into the page. -
Save your changes.