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:
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.