This project is not covered by Drupal’s security advisory policy.

Content Like

Content Like provides a simple AJAX like/unlike feature for Drupal content.
It supports both authenticated users and anonymous visitors.

Features

  • AJAX like/unlike functionality
  • Like count display
  • Supports nodes and custom block content
  • Authenticated users are tracked by Drupal user ID
  • Anonymous users are tracked using a browser cookie
  • Prevents duplicate likes using a database unique key
  • Admin configuration for enabled content types and custom block types
  • Works with default Drupal Twig templates
  • Supports custom Twig templates
  • Lazy builder rendering to reduce cache-related liked-state issues

Configuration

After enabling the module, go to:

/admin/config/content/content-like

From this settings page, site administrators can select which content types
and custom block types should have the like feature enabled.

If a bundle is checked, the like widget is shown when that entity is rendered.
If a bundle is unchecked, the like widget is not shown.

How Authenticated Likes Work

For logged-in users, the module stores the Drupal user ID with the liked entity.
This prevents the same user from repeatedly liking the same content.

How Anonymous Likes Work

For anonymous visitors, the module creates a browser cookie named
content_like_anon_id. The raw cookie value is not stored directly
in the database. Instead, the module stores a hash of the anonymous ID.

This allows anonymous visitors to like and unlike content while reducing
repeated likes from the same browser.

Duplicate Prevention

The module stores likes in a custom database table and uses a unique key on:

  • Entity type
  • Entity ID
  • Liker type
  • Liker ID

This prevents duplicate likes for the same content by the same authenticated
user or anonymous cookie visitor.

Twig Usage

If your theme prints the normal content render array, the like widget appears
automatically:

{{ content }}

If your theme manually prints fields in a custom Twig template, print the
like widget manually:

{% if content.content_like is defined %}
  {{ content.content_like }}
{% endif %}

Requirements

  • Drupal 10 or Drupal 11
  • Node module
  • Block Content module

Permissions

The module provides the following permission:

Administer content like settings

Users with this permission can configure where the like feature is enabled.

Typical Use Cases

  • Blog post likes
  • Article likes
  • Custom block likes
  • Public content engagement tracking
Supporting organizations: 

Project information

Releases