Image
html
Series

Drupal basics: Metatag

Mastering Metatag: The essential guide for Drupal developers

Metatag module enables a Drupal content editor to populate any meta tags through a user-friendly, in-depth interface.

layout of the title and description metatag fields

Introduction

Before we get into the specifics of the module, what are meta tags and what is the point of them? Meta tags are vital because they provide search engines and social media platforms with key information about your content, impacting its visibility and presentation. In short, well-written meta tags have the power to attract more traffic to your website.

Installation

Using Composer is the way of adding a module recommended by Drupal, so run the following from the command line:

composer require drupal/metatag

Enable the module from the command line with the command:

drush en metatag

Metatag Defaults

The real strength of the Metatag module is the ability to set default values of meta tags, thus avoiding additional work when creating content. This functionality is achieved with the help of the Token module (which is installed and enabled automatically with Metatag).

In the Drupal user interface, navigate to Configuration > Search and metadata > Metatag. Default meta tags can be set for all pages (Global), particular entity types (e.g. Content, Taxonomy Term) and even event specific content types (e.g. Articles). Insert tokens to dynamically generate values, e.g.
[node:title]
will insert the title of the node. Click the link "Browse available tokens" to view a list of available tokens.

Metatag defaults

Page-specific meta tags

To enable content editors to override meta tag default values, add a meta tags field to the content type (in the same way you would add a text field, for example).

Meta tags field

The meta tags field will appear in the right sidebar when editing content.

Essential sub-modules

There are two sub-modules that come bundled with Metatag that can set the meta tags to provide social media plaforms with information about the webstoe content; Metatag Open Graph and Metatag Twitter Cards.

Enable these modules from the command line with:

drush en metatag_open_graph metatag_twitter_cards

These modules expose the meta tags that will send title, text, image and page link information to social media platforms to produce rich page summaries, for example:

Social media preview

Additional sub-modules

This article will not discuss all of the sub-modules bundled with Metatag, but here are a few others of note:

  • Metatag Views - Provides views integration for metatags.
  • Metatag Verification - Verifies ownership of a site for search engines and other services.
  • Metatag Custom Tags - Provides support to define and manage custom meta tags.

Schema.org Metatag module

Schema.org markup provides structured data that helps search engines understand the meaning and context of web page content, improving how that content is displayed and ranked in search results. The Schema.org Metatag module extends the Metatag module to provide a user interface for dynamically generating this data using the Token module. The full extent of Schema.org is beyond the scope of this article, but read this article for more information.

Conclusion

Metatag module provides a simple user interface for content editors to feed search engines and social media platforms information about their website content. Install it on your website now.

Tags

If you have any comments or a particular topic in mind for a future article, or if you'd like to explore contracting possibilities, please get in touch.