This recipe shows you how to use AdPlugg to place ads into the sidebar of your Shopify site's blog. Since the default Shopify theme, "Debut", doesn't have a sidebar for the blog by default, we also show you how to add one!
You can see a demo of what the end result of this recipe looks like on the AdPlugg Shopify sample site here.
Create An Ad
First, we need to create an AdPlugg Ad.
- From within your AdPlugg account, create an Ad and upload an ad image (see the Ad Help Page for details).
Add the AdPlugg SDK to Your Shopify Theme
Next we are going to add the AdPlugg SDK to your Shopify Theme. This allows you to place and run AdPlugg ads throughout your Shopify site.
- From inside the Shopify admin, go to Online Store > Themes.
- Under the Actions menu for your current theme, click Edit Code.
- In the file tree on the left, under Layout, click theme.liquid.
- From within your account at adplugg.com, click Download and then Snippet.
- Click the Get The Snippet button at the bottom.
- Copy the AdPlugg SDK and paste it into the theme.liquid file right after the opening <head> tag.
- Press the Save button.
Now we are going to add a sidebar to your Shopify theme's blog. This is necessary for themes such as Shopify's default "Debut" theme.
- From inside the Shopify admin, go to Online Store > Themes.
- Under the Actions menu for your current theme, click Edit Code.
- In the file tree on the left, under Templates, click article.liquid.
- Change line 16 as follows. Note that this tells the blog content to only use 2/3s of the page.
From:
<div class="grid__item medium-up--five-sixths medium-up--push-one-twelfth">
To:
<div class="grid__item medium-up--two-thirds">
- Right after the closing tag for that div (on line 18), add the following code. Note that this will add a custom-content section and tell it to use 1/3 of the page. This will be our right sidebar!
<div class="grid__item medium-up--one-third">
{% section 'custom-content' %}
</div>
If you open one of your blog post pages, you should now see a right sidebar with the default custom-content text. Read on for how to modify this and add your ads.
Add an AdPlugg Ad to the Shopify Blog Article Sidebar
Now we are going to add our AdPlugg ad to the Shopify site's blog article sidebar.
- From inside the Shopify admin, go to Online Store > Themes.
- Click the "Customize" button for your current theme.
- At the top, there is a dropdown for the page that you are currently customizing. It defaults to "Home page". Change it to "Blog posts".
- Click on the "Custom content" section in the sections panel on the left.
- Remove the value from the Heading field. Note that you can, of course, also keep this or change it to something else if you want.
- Click the back arrow ( < ) in the Shopify sidebar to get back to the tree (while keeping the Custom content section selected). Below where it says "Custom content" in the sidebar, click "Add block" and choose the "Custom HTML" block. This will add a Custom HTML block to your sidebar.
- In the AdPlugg admin, copy the Ad Tag to your clipboard. You can get the Ad Tag by going to Downloads > Snippet and then pressing the Get the Snippet button.
- Paste the AdPlugg Ad Tag into the HTML box in Shopify.
- Press the "Save" button to save your changes.
Your ads should now start serving into the right sidebar on your Shopify site's blog articles!
Now we are going to add a sidebar to your Shopify theme's blog index. This is the main page for the blog that lists the articles.
- From inside the Shopify admin, go to Online Store > Themes.
- Under the Actions menu for your current theme, click Edit Code.
- In the file tree on the left, under Sections, click blog-template.liquid.
- At line 27, insert the following line just above the for loop, like so:
From:
{% for article in blog.articles %}
To:
<div class="grid__item medium-up--two-thirds">
{% for article in blog.articles %}
- After the end of the for loop (on line 109), add the following code. Note that this will close the 2/3 div that we created above and add a 1/3 sidebar.
</div>
<div class="grid__item medium-up--one-third">
%%SIDEBAR%%
</div>
- Those two changes covered grid view, now we'll do list view. At line 128, insert the following 2 lines just above the for loop, like so:
From:
{% for article in blog.articles %}
To:
<div class="grid">
<div class="grid__item medium-up--two-thirds">
{% for article in blog.articles %}
- After the end of the for loop (on line 203), add the following code. Note that this will close the 2/3 div that we created above and add a 1/3 sidebar.
</div>
<div class="grid__item medium-up--one-third">
%%SIDEBAR%%
</div>
</div>
- Next, back in the file tree on the left, under Templates, click blog.liquid. Replace the entire default contents of this file with the following code and save the file. Note that this will create a custom section and inject it at the location of the '%%SIDEBAR%%' placeholder that we created above (shout out to Jon Schwartz for originating the Nested Sections strategy that we are using here).
{% comment %}
The contents of the blog.liquid template can be found in /sections/blog-template.liquid
{% endcomment %}
{% capture sidebar_content %}
{% section 'custom-content' %}
{% endcapture %}
{% assign sidebar_content = sidebar_content | replace: 'class="shopify-section index-section"', 'class="shopify-section-nested index-section"' %}
{% capture template_content %}
{% section 'blog-template' %}
{% endcapture %}
{% assign template_content = template_content | replace: "%%SIDEBAR%%", sidebar_content %}
{{ template_content }}
If you open your main blog page, you should now see a right sidebar with the default custom-content text. Read on for how to modify this and add your ads.
Add an AdPlugg Ad to the Shopify Blog Index Sidebar
Now we are going to add our AdPlugg ad to the sidebar of our Shopify blog index page. This is basically the same as what we did above for the blog article pages but now we are going to do it for the main blog index page.
- From inside the Shopify admin, go to Online Store > Themes.
- Click the "Customize" button for your current theme.
- At the top, there is a dropdown for the page that you are currently customizing. It defaults to "Home page". Change it to "Blog".
- Click on the "Custom content" section in the sections panel on the left.
- Remove the value from the Heading field. Note that you can, of course, also keep this or change it to something else if you want.
- Click the back arrow ( < ) in the Shopify sidebar to get back to the tree (while keeping the Custom content section selected). Below where it says "Custom content" in the sidebar, click "Add block" and choose the "Custom HTML" block. This will add a Custom HTML block to your sidebar.
- In the AdPlugg admin, copy the Ad Tag to your clipboard. You can get the Ad Tag by going to Downloads > Snippet and then pressing the Get the Snippet button.
- Paste the AdPlugg Ad Tag into the Custom HTML block in your Shopify admin.
- Press the "Save" button to save your changes.
Your ads should now start serving into the right sidebar on your Shopify blog index page!
Adding More Ads!
You can add Ad Tags into other areas of your site using the same technique that we used above. You can also use AdPlugg Zones to serve different (or the same) ads into different places on your site.