Adding Buy Button code to HTML
After you创建一个购买按钮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.
Adding embed code to WordPress
You can add embed code to posts, pages, or templates on your WordPress site.
Add embed code to a WordPress post or page
- In Shopify,创建一个购买按钮and copy its embed code from theEmbed Codedialog (or clickCopy embed code to clipboard).
- From your WordPress dashboard, go to your posts or pages.
- Either create a new post or page, or edit an existing one.
- Inside the block editor, click the+button, search forCustom HTML, and then click to insert a Custom HTML block.
- 粘贴embed code into the text field provided by the Custom HTML block.
- Optional: Move the Custom HTML block or preview how your Buy Button will appear:
- To move the Custom HTML block, click the arrow buttons in the block's toolbar, or drag the block to a new location.
- To preview the Buy Button, clickPreviewon the block toolbar.
- When you're done, click theSave Draft,Preview, orPublishbutton for your post or page.
If you use WordPress'sClassic Editor Plugin, then instead of using a Custom HTML block, change the text editor fromVisualtoTextmode and paste the embed code in the editor.
Add embed code to a WordPress template
If your WordPress theme supports the site editor, then you can add an Embedded Buy Button to any of your site’s templates.
Steps:
- In Shopify,创建一个购买按钮and copy its embed code from theEmbed Codedialog (or clickCopy embed code to clipboard).
- In your WordPress dashboard, go to theEditor.
- Navigate to the template that you’d like to edit.
- Inside the block editor, click the+button, search forCustom HTML, and then click to insert a Custom HTML block.
- 粘贴embed code into the text field provided by the Custom HTML block.
- Optional: Move the Custom HTML block or preview how your Buy Button will appear:
- To move the Custom HTML block, click the arrow buttons in the block's toolbar, or drag the block to a new location.
- To preview the Buy Button, clickPreviewon the block toolbar.
- When you're done, click thePreview, orSavebutton for the template.
Adding embed code to your Shopify blog
Steps:
- From your Shopify admin, go to欧宝体育官网入口首页>Blog Posts.
- From theShopify app, tapStore.
- In theSales channelssection, tap欧宝体育官网入口首页.
- TapBlog posts.
- From theShopify app, tapStore.
- In theSales channelssection, tap欧宝体育官网入口首页.
- TapBlog posts.
- From theBlog Postspage, click the title of a blog post you want to edit, or clickAdd blog postto create a new one.
- In theWrite your blog postsection, clickShow HTMLin the rich text editor.
- Paste your embed code into the main text field.
- ClickSave.
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 thePage Contentarea, and then clickEDIT.
- Click the insert point where you want to add the embed code.
- In theMoresection of theContent Blocksdialog, clickCode.
- From your Shopify admin, copy the embed code from theEmbed Codedialog.
- From your Squarespace dashboard, paste the embed code into theCODEdialog. Make sure that the text field is set to receiveHTML.
- ClickAPPLYon theEDIT CODEdialog.
- ClickSAVEagain 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启用或说able Ajax.
Adding embed code to Wix
After you'vecreated a Buy Button or collectionin your Shopify admin, you can add it to your Wix website using the Wix Website Editor.
如果你想display more than one product on your Wix website without editing the embed code, then you can embed a collection. You cancreate a new collectionin your Shopify admin for the products that you want to display on Wix.
Steps:
- From your Shopify admin,创建一个购买按钮for a product or collection, and then copy its embed code.
- From your Wix account, find the site you want to edit in theMy Sitessection, and then clickEdit Site.
- In the Wix Website Editor, click the
+
button, and then clickMore. - ClickHTML Codeto add an HTML code widget to the page.
- ClickEnter Code.
- On theHTML Settingsdialog, paste the embed code for your Buy Button or collection in theAdd your code here字段,然后单击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, clickSave.
Embed multiple products or collections
Steps:
- From your Shopify admin,创建一个购买按钮for a product or collection, and then copy its embed code.
- 粘贴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 theMy Sitessection, and then clickEdit Site.
- In the Wix Website Editor, click the
+
button, and then clickMore. - ClickHTML Codeto add an HTML code widget to the page.
- ClickEnter Code.
- On theHTML Settingsdialog, paste the edited code for your Buy Buttons in theAdd your code here字段,然后单击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, clickSave.
Add script tags separately
Some platforms (like Unbounce) require that you paste the embed code'stags 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 theelement and the
element. For example:
Open the page header for the website where you want to embed a Buy Button.
粘贴entire
element in the page header.
Save your changes.
From the original embed code in your Shopify admin, copy only the
element. For example:Open the page on your website where you want to embed a Buy Button.
粘贴
code snippet into the page.Save your changes.
Ready to start selling with Shopify?
Try it free