Anti-Spam Blog Comments

Network security

If your blog articles include an option to leave a comment, you can block SPAM by requiring user login and stripping HTML from their remarks.

Publish Insights 22 January 2022

Spam Protection

Do your blog articles include an option to leave a comment? If so, many visitors may pack it with SPAM or troll remarks. As a defense, Shopify comments (among more robust alternatives) include a moderation feature. The site administrator can read and approve visitor comments before they show up in the blog.

Approve More Comments

Strip HTML Comments

Many comments that begin with a nice message remain unapproved because they include URLs or other HTML formatting. With a simple modification to your Shopify theme, you can strip out the HTML and truncate the comment when encountering a URL. For this, use the programming language called Liquid.

Before making modifications to your Shopify theme, it is good to duplicate it. Within Admin, under the lefthand navigation, choose Online Store: Themes. Click the menu for the active theme, Actions: Duplicate. Work on the duplicate and preview before activating when done.

Caution: Modifying Liquid code may invalidate your theme for future updates by the developer. Anything you add will require manual migration to a different theme, with possible incompatibility.

Now you access the Liquid programming code with Actions: Edit code menu. Within the Sections area, open your article-template. (For older themes without a Sections area, open the article.liquid under the Templates section.)

Scroll to the bottom to insert the following code:

{% if == %}
  {{ comment.content }}
{% else %}
  {{ comment.content | strip_html | split: 'http' | first | remove: 'www' }}
{% endif %}

This allows the blog author to leave unrestricted comments (with a URL) but prohibits others from doing so. (Shopify retains the full comments but only displays the truncated versions with this modification.)

Blogs have their value from an SEO standpoint. With the proliferation of multimedia social media platforms, reading words for entertainment may seem to be as esoteric as opera audiences. Most visitors scan a page of text in under a minute, looking for videos, subheads, and pull quotes to get the gist of what is going on.

Read next article

'Hairstylist trimming hair'
'Web camera'