Optimizing the comment functionality on your Drupal website

If you want commenting to be a nice experience on your Drupal website then follow these tips making commenting easy, setting up comment notifications and learn how to fight SPAM.
Robert Roose
Door Robert Roose

Optimizing the comment functionality on your Drupal website

Why you should enable comments on your Drupal website

Comments are a great way for users to interact with your website. It gives them the ability to ask you about the stuff you write. This can give you new insights on what to write about. It also opens up the possibility to improve your content when something is not clear or when you got something wrong. 

Comments also improve the SEO of your Drupal website. Because commenters tend to reuse important keywords, when asking questions or discussing the content you’ve written. Also, every time a new comment is posted, search engines such as Google will view this an update to the original post. Signalling that the content is being updated, which in most cases it is because you clarify things or answer questions.

Don’t be afraid to open up comments. Of course someone can disagree with you, which doesn’t have to be bad. It gives you an opportunity to restate your point or maybe change the way you think about things.

Then there are spammers, which can easily be blocked with Cleantalk (which I will discuss later in this post) and people who mean harm by posting weird or offensive stuff. The chance you get these types of people to comment on your content are very slim. And even then you can just quickly delete them when you got your notification setup correctly (which I will get to below).

Why host your own comments and not use comment services such as disqus

Instead of using the Drupal comment functionality you can also outsource this by using external comments services such as Disqus. I would advise against this, because:

  • The comments are not your own. What happens if the service goes out of business? All the valuable comments (and content) would be gone.
  • Most services wrap the comments in a JavaScript container avoiding search engines such as Google to index them correctly. The SEO benefits of having comments on your site would be non-existent.
  • The big advantage of outsourced comment services, such as Disqus, is blocking the SPAM, but if you use Cleantalk (more about this service below) you can easily do this yourself.

Setting up comments

If you want people to post comments on your Drupal website you first need to enable the comments module which comes with the Drupal core. After that, you can add a new field to the content type you want people to comment on. As a field type select Comments.

I like to enable Threading so you can create a visual distinction when someone replies on a comment. I set the comments per page to 999. I want all the comments to show on the same page without pagination. Next is set Anonymous commenting to Anonymous posters may leave their contact information. This will enable users to comment anonymously, but also have the ability to enter their name and/or email. Making sure users can enter their email is important when using the Comment notify module, but I will get to that later in this post. 

Create a better way to add and reply to comments

The default comment functionality is fine, but to make the user experience even better you can install the Ajax Comments module. This module replaces the comment form with a version powered with Ajax. When a user posts a comment, only the comment section will be reloaded, instead of the whole page. Also, when replying on a comment the comment form will be loaded directly under the comment instead of redirecting to a new page. 

After installing the module you can enable the Ajax comments functionality on the display tab of the content type that has a comment field.

Notify users when they get a reply on their comment

Another great way to keep your visitors engaged is by giving them the option to get an email when someone replies to their comment. Thanks to the Comment Notify module this is easily added to any Drupal website. 

After installing and enabling the module you can navigate to Configuration > People > Comment notification to configure this module to your own preferences. Here you can select the comments field you want notification to be available. 

I like to disable All comments below Available subscription modes as I don’t think this will be used a lot and can only be confusing. Under Default state for the notification selection box I select Replies to my comment so the comment notification is checked by default. 

If you also check Subscribe users to their entity follow-up notification emails by default node authors get an email when someone comments on their content.

Below you can edit the emails which will be sent by the Comment Notify module.

After you save the configuration navigate to People > Permissions and enable Subscribe to comment notifications for anonymous and authenticated users.

If you go to the comment form on the frontend you will see an extra checkbox below the text area which can be used to enable or disable notifications. 

Fight spam with Cleantalk

If you enable comments on your Drupal website you will probably get SPAM comments in no time. Deleting these comments manually can be labour intensive because, if your Drupal website is even somewhat popular, you will get at least fifty SPAM comments on a daily basis. There are a lot of modules available to fight SPAM and I’ve tried them all. I used to work with the Google ReCaptcha module but it was acting up all the time. Giving weird errors or just stopped working all together. Also the Google ReCaptcha isn’t accessible for everyone and makes it harder for visitors to post comments. 

By chance I landed on a blog post by Jeff Geerling who had the same issues fighting SPAM comments on his Drupal website. His solution is to use Cleantalk. Cleantalk is a service that helps you fight SPAM. There is a module available for Drupal, but there is one catch: It’s a paid service. Luckily it’s very inexpensive (only 8 dollars a year) considering how much time it can save you. 

I’ve been using Cleantalk for almost a month now and so far I’m very pleased. I’ve only had two SPAM comments (instead of thousands) come through. If this happens you can mark these comments as SPAM in the Cleantalk control panel. This will help make the service better understand what is considered SPAM and what’s not. 

I’ve had one issue where someone posted a legitimate comment, but was marked as SPAM. This was because of the IP range which Cleantalk blacklisted. So it’s wise to sometimes go through the Cleantalk logs and see if there are any comments that unjustly have been marked as SPAM.

Have any questions setting up comments on your Drupal website?

Leave a comment and I will get back to you ASAP. Also don’t forget to subscribe to my Drupal newsletter or follow my Drupal RSS feed!

More blogs to optimize your Drupal site

The content of this field is kept private and will not be shown publicly.

Beperkte HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.

Comments

Great post!

On Drupal 7 the links on the front page used to include the number of comments to everyone, and the number of NEW comments to those authorized to comment. I don't get a count of new comments any more, even though new comments are marked on the full node comment section.

Hi Michael, 

Unfortunately it's very difficult for me to help you as Drupal installations can get very complex. 

Have you tried Drupal Answers?

Thanks for this very clear article.
Would you know how to display a comment's ID next to its permalink? Or even as the label of the permalink - to save space?
Many thanks in advance.

Hi Stado,

You're welcome :) You can probably accomplish this by either:

  • Editing the comment.html.twig located in /core/modules/comment (first copy it to your theme folder)
  • Replacing the comments overview with your own created view. This will probably be a bit harder but you will have more control what information is shown.

Good luck!

When I originally commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I
get four emails with the same comment. Is there any way you
can remove people from that service? Many thanks!

I've had more complaints about this issue so I temporarily disabled the comment notify functionality.

Sorry for the inconvenience.