Drupal is a registered trademark of Dries Buytaert
Release: Excel Serialization 2.1.2 Minor update available for module xls_serialization (2.1.2). Release: Time Zone Field 8.x-1.14 Minor update available for module tzfield (8.x-1.14). Module Revived: Entity API 8.x-1.7 Module entity updated after 17 months of inactivity (8.x-1.7). Release: Vartheme Bs5 4.1.1 Minor update available for theme vartheme_bs5 (4.1.1). Release: Varbase Heroslider 1.1.3 Minor update available for module varbase_heroslider (1.1.3). Release: Varbase Demo 1.1.2 Minor update available for module varbase_demo (1.1.2). Release: Varbase Dashboards 2.0.3 Minor update available for module varbase_dashboards (2.0.3). Release: Varbase AI 2.0.9 Minor update available for module varbase_ai (2.0.9). Release: Varbase Workflow 3.1.2 Minor update available for module varbase_workflow (3.1.2). Security Coverage: Role Aware Maxlength Module role_aware_maxlength now has official Drupal security advisory coverage.

This module automatically generates metatags such as title, description, and keywords for content nodes using AI. It can be configured to strip HTML and to use custom prompts per language, with an option to generate metatags with a single click from the node edit form.

AI Metatag Generator

A Drupal module that leverages AI to automatically generate metatags based on the content
(title, description, keywords, abstract) for content nodes.

Features

  • AI-powered metatag generation (title, description, keywords, abstract) from node view
  • Per-language prompt configuration
  • Default prompt template with language placeholder
  • Configurable content types and metatag field
  • Selectable AI provider and model
  • HTML content stripping and cleanup
  • One-click AJAX generation from node edit forms
  • Success/error feedback via modal dialog popups
  • Comprehensive error handling with try-catch and logging

Requirements

  • Drupal 10+
  • AI module (`drupal/ai`)
  • Metatag module (`drupal/metatag`)
  • PHP 8+

Installation

  1. Enable the module via Drupal admin or Drush: drush en ai_metatag_generator
  2. For site-wide installation, add to core.extension.yml

Configuration

Navigate to Configuration > AI > AI Metatag Generator
(`/admin/config/ai/ai-metatag-generator`).

Settings

  • Content Types: Select which content types allow AI metatag generation.
  • Meta tag field machine name: The metatag field on the content type (e.g. `field_meta_tag`).
  • AI Provider and Model: Select the AI provider/model for chat operations. Falls back to the default provider if not set.
  • Content Processing:
    • Strip HTML Tags: Remove HTML before sending to AI.
    • Display Mode: View mode used to render node content. (default: `full`)
  • Prompts
    • Default Prompt: A read-only reference prompt showing the template used when no language-specific prompt is set.
    • Per-language prompts: Customize the prompt for each enabled language.

Default Configuration

content_types: {}
metatag_field: 'field_meta_tag'
provider_model: ''
strip_html: true
display_mode: 'full'
prompts: {}
black_list: ''

Usage

From Node Edit Forms

  1. Edit a node of an enabled content type that has the configured metatag field.
  2. Click Generate Metatags with AI in the advanced sctions area under metatag.
  3. The module will:
    • Render the node content using the configured display mode.
    • Strip HTML if configured.
    • Send content to the AI provider with the language-specific prompt (or the default prompt).
    • Parse the JSON response.
    • Populate the metatag form fields (title, description, keywords, abstract) via AJAX.
  4. A popup dialog confirms success or displays errors.
  5. Review and save the node to apply changes.

Programmatic Usage

$ai_service = \Drupal::service(
  'ai_metatag_generator.ai_service'
);

// Generate metatags for a node.
$metatags = $ai_service->generateMetatags($node);
// Returns: ['title' => ..., 'description' => ...,
//   'keywords' => ..., 'abstract' => ...] or NULL.

// Update node metatag fields.
$ai_service->updateNodeMetatags($node, $metatags);

Permissions

  • Administer AI Metatag Generator: Configure module settings (`administer ai metatag generator`).
  • Use AI Metatag Generator: Generate metatags for content (`use ai metatag generator`)

Error Handling

  • All service methods and form handlers use try-catch blocks with logging to the `ai_metatag_generator` channel.
  • AJAX errors are displayed in modal dialog popups.
  • Configuration save failures show messenger errors.
  • AI provider unavailability is handled gracefully with a user-facing message on the config form.

Development

Running Tests

All tests

./vendor/bin/phpunit <module_path>/ai_metatag_generator/tests/

Specific test

./vendor/bin/phpunit <module_path>/ai_metatag_generator/tests/src/Unit/Services/AiMetatagServiceTest.php

Code Standards

./vendor/bin/phpcs <module_path>/ai_metatag_generator/

Troubleshooting

  • Generate button not showing: Check that the node's content type is selected in config, the metatag field name matches, the node is not new, and the user has the use ai metatag generator permission.
  • AI calls failing: Verify the AI module is configured with valid API keys and a chat provider is available.
  • Empty responses: Check the prompt template.
  • Config form errors: If AI providers fail to load, the form will display an error message instead of settings.
  • AJAX requests prevent page reloads
  • Asynchronous processing for better user experience

Support

For issues related to this module, check:

  1. Module configuration at /admin/config/ai/ai-metatag-generator
  2. Drupal logs at /admin/reports/dblog
  3. AI module configuration
  4. Network connectivity to AI services

Activity

Tracked releases
3
Tracked since
Apr 2026
Latest release
1 month ago
Releases (12 mo)
3 ▲ from 0
Maintenance
Active

Release Timeline

Releases

Version Type Release date
1.0.0-alpha3 Pre-release Jul 6, 2026
1.0.0-alpha2 Pre-release Jun 9, 2026
1.0.0-alpha1 Pre-release Apr 14, 2026