Home / Shopify DIY / Members-only blog via custom theme templates

Members-only blog via custom theme templates

Update Nov 2023

This article works in non-sectioned themes.  For a version that works out of the box with the Dawn theme, see this article: Restricted Blog in Dawn

 




In this guide we’ll show you how to create customizable gated content (a paywall) so that some content is only accessible to certain customers, using a custom blog and article template. Just like the one you can see here: https://www.pogodan.com/blogs/members-only

We'll assume for the purposes of this guide that you're already using a subscription app or have some other group of customers that you want to offer special access to, and all those customers are tagged with a specific tag. If you're using a subscription app, they will likely already be tagged.

Our members are tagged "member". 

Create two new templates

In the theme we're using, both the blog and the article only have a reference to a section template in them. In your theme there may be more code in there, in which case you'll need to modify the code accordingly.

In the code editor, create two new files, blog.protected-content and article.protected-content and replace them with this code. Note that the sections template--blog and template--article are sections used in the theme, so if yours are named differently, adjust the section names.

If you're using a different tag than "member" or you're using a metafield or something else to determine if the customer has access, you will need to modify line 1 on both of these templates.

blog.protected-content.liquid

https://raw.githubusercontent.com/lerkens/shopify-restricted-content/main/templates/blog.protected-content.liquid#

{% if customer.tags contains 'member' %}
  {% section 'template--blog' %}
{% else %}  
  {% section 'template--protected-content' %}
{% endif %}

article.protected-content.liquid

https://raw.githubusercontent.com/lerkens/shopify-restricted-content/main/templates/article.protected-content.liquid

{% if customer.tags contains 'member' %}
  {% section 'template--article' %}
{% else %}  
  {% section 'template--protected-content' %}
{% endif %}

Add the protected content section

Create a new section called template--protected-content.liquid

Paste in the contents of this file.  

Create your content

Add a new blog in Shopify. Make sure to select the "protected-content" template. Then add an article, again selecting the "protected-content" template.

Need Help?

This article and code snippets are designed for you to be able to do this yourself, but if you don't feel comfortable or want us to install the code for you, you can purchase our installation service.

Install it for me 

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.

Sports & Membership Programs

Every Membership Program is a little bit different. Our clients often find that the app they found in the app store does 90% of what they need, but that missing 10% is critical to their value proposition. Or the app was working fairly well until they started to scale, and now they spend too much time on repetitive tasks and need an automation.

We can help plug these gaps or build something completely custom for you. We've helped dozens of merchants with issues just like this, and we can help you too.