Drupal - How do I add a specific meta-tag to all the pages of a site?

You can use the Metatag module for this, in order to add meta tags to every page of your site:

enter image description here

If you want to do it by coding, it is possible to implement the theme_preprocess_html hook to add the meta tag manually:

function theme_preprocess_html(&$variables)
{

    $noindex = [
            '#tag' => 'meta',
            '#attributes' => [
                'name' => 'robots',
                'content' => 'noindex',
            ],
        ];
    $variables['page']['#attached']['html_head'][] = [$noindex, 'noindex'];
}

(more details here: https://stackoverflow.com/questions/35913739/add-meta-tag-to-head-in-drupal-8)


You can also add a robots.txt file with the following content in your docroot:

User-agent: *
Disallow: /

You can find more information about this in The Web Robots Pages.

Tags:

Meta Tags

8