Drupal is a registered trademark of Dries Buytaert
Reading Time Estimator Module

Overview

The Reading Time Estimator module calculates and displays the estimated reading time for content based on configurable text fields. It automatically analyzes the word count from selected fields and displays a user-friendly reading time estimate on node pages.

Features

  • Configurable Reading Speed: Set custom words-per-minute reading speed (default: 200 WPM)
  • Content Type Support: Configure which text fields to include for each content type
  • Automatic Calculation: Automatically calculates reading time based on selected fields
  • Display Management: Reading time can be enabled/disabled per content type via the display settings
  • Template Support: Customizable Twig template for displaying reading time
  • Cache Integration: Properly integrated with Drupal's cache system

Installation

  1. Place the module in /web/modules/custom_modules/reading_time_estimator/
  2. Enable the module via Drush:

    drush en reading_time_estimator
    

    Or via the admin interface at /admin/modules

  3. Clear Drupal cache:

    drush cr
    

Configuration

Basic Configuration

  1. Navigate to ConfigurationReading Time Estimator Settings (/admin/config/content/reading-time-estimator)

  2. Set Reading Speed:

    • Configure the average reading speed in words per minute
    • Default: 200 words per minute
    • Range: 50-500 WPM
  3. Configure Content Types:

    • For each content type, select which text fields should be included in the reading time calculation
    • Only text fields (text_long, text_with_summary, string_long, text) are available for selection
    • You can select multiple fields per content type

Display Settings

  1. Navigate to StructureContent types[Your Content Type]Manage display

  2. Find the Reading Time Estimate component in the disabled section

  3. Enable and configure the component:

    • Drag it to the desired position
    • Configure visibility settings if needed
    • Save the configuration

How It Works

  1. Field Selection: The module analyzes text from the fields you've configured for each content type
  2. Word Counting: It strips HTML tags, decodes entities, and counts words in the selected fields
  3. Calculation: Reading time = Total words ÷ Reading speed (minimum 1 minute)
  4. Display: The reading time is displayed using the reading-time-estimate.html.twig template

Usage

Display Reading Time

Once configured, the reading time estimate will automatically appear on node pages where:

  • The content type has fields configured in the module settings
  • The "Reading Time Estimate" component is enabled in the display settings
  • The node has content in the selected fields

Customizing the Display

The reading time is rendered using the reading-time-estimate.html.twig template located at:

templates/reading-time-estimate.html.twig

You can override this template in your theme to customize the appearance.

Available Variables:

  • reading_time: The estimated reading time in minutes (integer)

Example Override:

{# In your theme's templates/reading-time-estimate.html.twig #}
<div class="custom-reading-time">
  <i class="icon-clock"></i>
  <span>{{ reading_time }} min read</span>
</div>

Styling

The module includes basic CSS in css/reading-time-estimate.css. You can override styles in your theme:

.reading-time-estimate {
  /* Your custom styles */
}

Programmatic Usage

Calculate Reading Time Programmatically

use Drupal\reading_time_estimator\Service\ReadingTimeCalculator;

// Get the service
$calculator = \Drupal::service('reading_time_estimator.calculator');

// Calculate reading time for a node
$node = Node::load(123);
$reading_time = $calculator->calculateReadingTime($node);

// $reading_time will be an integer representing minutes

Get Available Text Fields

$calculator = \Drupal::service('reading_time_estimator.calculator');
$available_fields = $calculator->getAvailableTextFields('article');

// Returns array of field names and labels
// ['body' => 'Body', 'field_summary' => 'Summary']

Technical Details

Hooks Implemented

  • hook_entity_extra_field_info(): Adds "Reading Time Estimate" as an extra field for all node types
  • hook_ENTITY_TYPE_view(): Calculates and displays reading time when the component is enabled
  • hook_theme(): Registers the reading time estimate template

Services

  • reading_time_estimator.calculator: Main service for calculating reading time
    • Class: Drupal\reading_time_estimator\Service\ReadingTimeCalculator
    • Dependencies: config.factory, entity_field.manager

Configuration Schema

The module stores configuration in reading_time_estimator.settings:

  • reading_speed: Integer (words per minute)
  • content_types.{bundle}.fields: Array of field names to include

Requirements

  • Drupal 9, 10, or 11
  • PHP 7.4 or higher
  • Dependencies:
    • drupal:field
    • drupal:node

Troubleshooting

Reading Time Not Displaying

  1. Check Configuration:

    • Ensure fields are selected for the content type in module settings
    • Verify the content has text in the selected fields
  2. Check Display Settings:

    • Navigate to the content type's display settings
    • Ensure "Reading Time Estimate" component is enabled and visible
  3. Clear Cache:

    drush cr
    

Reading Time Shows 0 or Incorrect

  1. Verify Field Selection: Make sure the correct fields are selected in configuration
  2. Check Field Content: Ensure the selected fields contain actual text content
  3. Review Reading Speed: Adjust the reading speed setting if estimates seem off

Development

File Structure

reading_time_estimator/
├── css/
│   └── reading-time-estimate.css
├── src/
│   ├── Form/
│   │   └── ReadingTimeEstimatorConfigForm.php
│   └── Service/
│       └── ReadingTimeCalculator.php
├── templates/
│   └── reading-time-estimate.html.twig
├── reading_time_estimator.info.yml
├── reading_time_estimator.libraries.yml
├── reading_time_estimator.links.menu.yml
├── reading_time_estimator.module
├── reading_time_estimator.routing.yml
├── reading_time_estimator.services.yml
└── README.md

Extending the Module

To add custom field types for reading time calculation, modify the getAvailableTextFields() method in ReadingTimeCalculator.php:

// Add custom field types
if (in_array($field_type, ['text_long', 'text_with_summary', 'string_long', 'text', 'your_custom_type'])) {
  $fields[$field_name] = $field_definition->getLabel();
}

Support

For issues or feature requests, please contact the development team or create an issue in the project repository.

License

This module is part of the TTN Drupal project.

Activity

Total releases
1
First release
Feb 2026
Latest release
1 month ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
1.0.0 Stable Feb 1, 2026