Dev HOWTO: Add a new meta tag to an existing module, suitable for a patch
Last updated on
21 September 2023
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
Drupal 7
At a rudimentary level:
- Decide whether the new meta tags should go in the main module or a submodule,
- Edit that module's "*.metatag.inc" file,
- Scroll down to the hook_metatag_info() implementation,
- Duplicate some of the $info['tags'] variables
- Tweak the variable accordingly. note that the array key, .e.g. the 'robots' part of $info['tags']['robots'], is what defines the meta tag's name.
- Upload the patch and collaborate with others in the community to make sure it works as intended.
An example of inherited meta tag addition:
- Adding Meta Tags to Drupal Content: https://www.ostraining.com/blog/drupal/meta-tags/
Drupal 8
There are several steps necessary to create a new meta tag in Drupal 8:
- Create a new plugin file with the appropriate structure.
- Add lines in the config/schema/[MODULENAME].metatag_tag.schema.yml file
- Add the meta tag to the src/Tests/[MODULENAME]TagsTest.php file in the $tags array.
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion