I want to prevent Google from indexing my website. I know I need this meta tag added to the header.

<meta name="robots" content="noindex" />

How can I add this 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)

  • Thank you for your answer, i'd prefer if i can do this by code, with a hook for example ? – usethe23 Jan 25 '17 at 14:30
  • 2
    @usethe23, It is also possible. I have just edited my answer to add this possibility. – dinopmi Jan 25 '17 at 14:42

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.

  • 2
    Note that this prevents crawling, not (necessarily) indexing (details). – unor Jan 26 '17 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.