3 This module allows a site's builder to automatically provide structured
4 metadata, aka "meta tags", about the site and individual pages.
6 In the context of search engine optimization, providing an extensive set of
7 meta tags may help improve the site's and pages' rankings, thus may aid with
8 achieving a more prominent display of the content within search engine results.
9 They can also be used to tailor how content is displayed when shared on social
12 For additional information, see the online documentation:
13 https://www.drupal.org/docs/8/modules/metatag
15 This version should work with all Drupal 8 releases, though it is always
16 recommended to keep Drupal core installations up to date.
20 --------------------------------------------------------------------------------
21 Metatag for Drupal 8 requires the following:
24 https://www.drupal.org/project/token
25 Provides a popup browser to see the available tokens for use in meta tag
30 --------------------------------------------------------------------------------
31 The primary features include:
33 * An administration interface to manage default meta tags.
35 * Use of standard fields for entity support, allowing for translation and
36 revisioning of meta tag values added for individual entities.
38 * A large volume of meta tags available, covering commonly used tags, Open
39 Graph tags, Twitter Cards tags, Dublin Core tags, Google+ tags, App Links
40 tags, site verification tags and more; all but the basic meta tags are kept
41 in separate submodules.
43 * The fifteen Dublin Core Basic Element Set 1.1 meta tags may be added by
44 enabling the "Metatag: Dublin Core" submodule.
46 * Forty additional Dublin Core meta tags may be added by enabling the "Metatag:
47 Dublin Core Advanced" submodule.
49 * The Open Graph Protocol meta tags, as used by Facebook, Pinterest, LinkedIn
50 and other sites, may be added by enabling the "Metatag: Open Graph" submodule.
52 * The Twitter Cards meta tags may be added by enabling the "Metatag: Twitter
55 * Certain meta tags used by Google+ may be added by enabling the "Metatag:
58 * Facebook's fb:app_id, fb:admins and fb:pages meta tags may be added by
59 enabling the "Metatag: Facebook" submodule. These are useful for sites which
60 are using Facebook widgets or are building custom integration with Facebook's
61 APIs, but they are not needed by most sites and have no bearing on the
64 * The Pinterest meta tags may be added by enabling the "Metatag: Pinterest"
67 * Site verification meta tags can be added, e.g. as used by the Google search
68 engine to confirm ownership of the site; see the "Metatag: Verification"
71 * The Metatag: Mobile & UI Adjustments submodule adds the MobileOptimized,
72 HandheldFriendly, viewport, cleartype, theme-color, format-detection,
73 apple-mobile-web-app-capable, apple-mobile-web-app-status-bar-style, the
74 android-app and ios-app alternative link meta tags, and the Android manifest
77 * The hreflang meta tags are available via the Metatag:hreflang submodule.
79 * The App Links meta tags may be added by enabling the Metatag: App Links
82 * Support for meta tags specific to Google Custom Search Appliance are available
83 in the "Metatag: Google Custom Search Engine (CSE)" submodule.
85 * Meta tags specific to Facebook are included in the "Metatag: Facebook"
88 * A plugin interface allowing for additional meta tags to be easily added via
91 * Integration with DrupalConsole [1] to provide a quick method of generating new
95 Standard usage scenario
96 --------------------------------------------------------------------------------
97 1. Install the module.
98 2. Open admin/config/search/metatag.
99 3. Adjust global and entity defaults. Fill in reasonable default values for any
100 of the meta tags that need to be customized. Tokens may be used to
101 automatically assign values.
102 4. Additional bundle defaults may be added by clicking on "Add metatag
103 defaults" and filling out the form.
104 5. To adjust meta tags for a specific entity, the Metatag field must be added
105 first. Follow these steps:
107 5.1 Go to the "Manage fields" of the bundle where the Metatag field is to
109 5.2 Select "Meta tags" from the "Add a new field" selector.
110 5.3 Fill in a label for the field, e.g. "Meta tags", and set an appropriate
111 machine name, e.g. "meta_tags".
112 5.4 Click the "Save and continue" button.
113 5.5 If the site supports multiple languages, and translations have been
114 enabled for this entity, select "Users may translate this field" to use
115 Drupal's translation system.
118 Programmatically assign meta tags to an entity
119 --------------------------------------------------------------------------------
120 There are two ways to assign an entity's meta tags in custom module. Both
121 scenarios require a "Metatag" field be added to the entity's field settings, the
122 field name "field_meta_tags" is used but this is completely arbitrary.
126 $entity_type = 'node';
130 'title' => 'Testing metatag creation',
133 'field_meta_tags' => serialize([
134 'title' => 'Some title',
135 'description' => 'Some description.',
136 'keywords' => 'Some,Keywords',
139 $node = \Drupal::entityTypeManager()
140 ->getStorage($entity_type)
146 $node = Node::create([
152 $node->set('title', 'Testing metatag creation');
153 $node->set('field_meta_tags', serialize([
154 'title' => 'Some title',
155 'description' => 'Some description.',
156 'keywords' => 'Some,Keywords',
160 In both examples, the custom meta tag values will still be merged with the
161 values defined via the global defaults prior to being output - it is not
162 necessary to copy each value to the new record.
165 Obtain meta tags for an entity
166 --------------------------------------------------------------------------------
167 For developers needing to access the rendered meta tags for a given entity, a
168 function is provided to make this easy to do:
170 $metatags = metatag_generate_entity_metatags($entity);
172 This will return an array with the following structure:
179 'content' => 'The What | D8.4',
185 'rel' => 'canonical',
186 'href' => 'http://example.com/what',
192 'name' => 'description',
193 'content' => 'I can't even.',
199 'name' => 'generator',
200 'content' => 'Drupal 8!',
205 The meta tags are keyed off the meta tag plugin's ID, e.g. "generator". Each
206 meta tag is then provided as arguments suitable for use in a render array with
207 the type "html_tag". Extracting the value of the meta tag will depend upon the
208 type of meta tag, e.g. the generator meta tag uses the "content" attribute while
209 the link tag uses the "href" attribute.
212 DrupalConsole integration
213 --------------------------------------------------------------------------------
214 Using the DrupalConsole, it is possible to generate new meta tags, either for
215 use in new custom modules that require custom meta tags, or to create patches
216 for extending Metatag's options.
218 To generate a new tag, install DrupalConsole and then use the following command:
220 drupal generate:plugin:metatag:tag
222 This will guide the site builder through the necessary steps to create a new
223 meta tag plugin and add it to a module.
225 There is also a command for generating meta tag groups:
227 drupal generate:plugin:metatag:group
229 Again, this provides a guided process to create a new group.
233 --------------------------------------------------------------------------------
234 Some modules are available that extend Metatag with additional or complimentary
238 https://www.drupal.org/project/schema_metatag
239 Extensive solution for adding schema.org / JSON-LD support to Metatag.
242 https://www.drupal.org/project/context_metadata
243 Allow assignment of meta tags based upon different system contexts, e.g. per
246 * Real-time SEO for Drupal
247 https://www.drupal.org/project/yoast_seo
248 Uses the YoastSEO.js library and service (https://yoast.com/) to provide
249 realtime feedback on the meta tags.
252 https://www.drupal.org/project/metatag_cxense
253 Adds support for the Cxense meta tags used by their DMP and Insight services.
255 * Metatag Google Scholar
256 https://www.drupal.org/project/metatag_google_scholar
257 Adds support for a number of meta tags used with the Google Scholar system.
261 --------------------------------------------------------------------------------
262 * In order to uninstall the module any "Metatag" fields must first be removed
263 from all entities. In order to see whether there are fields blocking the
264 module from being uninstalled, load the module uninstall page
265 (admin/modules/uninstall) and see if any are listed, it will look something
267 The Meta tags field type is used in the following field:
269 In order to uninstall the module, go to the appropriate field settings pages
270 and remove the Metatag field listed in the message. Once this is done it will
271 be possible to uninstall the module.
275 --------------------------------------------------------------------------------
276 Currently maintained by Damien McKenna [2] and Dave Reid [3]. Drupal 7 module
277 originally written by Dave Reid. Early work on Drupal 8 port by Damien McKenna
278 and Michelle Cox [4], and sponsored by Mediacurrent [5]; key improvements by
279 Juampy Novillo Requena [6] with insights from Dave Reid and sponsorship by
280 Lullabot [7] and Acquia [8]. Additional contributions to the 8.x-1.0 release
281 from cilefen [9], Daniel Wehner [10], Jesus Manuel Olivas [11], Lee Rowlands
282 [12], Michael Kandelaars [13], Ivo Van Geertruyen [14], Nikhilesh Gupta B [15],
283 Rakesh James [16], and many others.
285 Ongoing development is sponsored by Mediacurrent.
287 The best way to contact the authors is to submit an issue, be it a support
288 request, a feature request or a bug report, in the project issue queue:
289 https://www.drupal.org/project/issues/metatag
293 --------------------------------------------------------------------------------
294 1: https://www.drupal.org/project/console
295 2: https://www.drupal.org/u/damienmckenna
296 3: https://www.drupal.org/u/dave-reid
297 4: https://www.drupal.org/u/michelle
298 5: https://www.mediacurrent.com/
299 6: https://www.drupal.org/u/juampynr
300 7: https://www.lullabot.com/
301 8: https://www.acquia.com/
302 9: https://www.drupal.org/u/cilefen
303 10: https://www.drupal.org/u/dawehner
304 11: https://www.drupal.org/u/jmolivas
305 12: https://www.drupal.org/u/larowlan
306 13: https://www.drupal.org/u/mikeyk
307 14: https://www.drupal.org/u/mr.baileys
308 15: https://www.drupal.org/u/nikhilesh-gupta
309 16: https://www.drupal.org/u/rakeshgectcr