Often on a website, you want to control what pages are displayed in search results. You can do this by adding the noindex meta tag to pages. I’m not going to cover why you would want some pages not to appear in the search results; however, I want to show you how to implement it in Drupal.
This tutorial will teach you how to use the Metatag module to control the noindex meta tag.
If you want to learn more about Metatag, read our tutorial “Getting Started with Metatag in Drupal”.
Drupal SEO Series using Metatag
1. Getting Started with Metatag Module in Drupal
2. Generate Twitter Card Meta Tags using Metatag in Drupal
3. Generate Open Graph Meta Tags for Facebook using Metatag in Drupal
4. Automatically Generate URL Aliases using Pathauto in Drupal
5. Manage URL Redirects using Redirect module in Drupal
6. Generate Sitemaps using Simple XML Sitemap in Drupal
Let’s begin by downloading the Metatag module using Composer.
Run the following command:
composer require drupal/metatag
Then go to Extend and install the Metatag module.
Configure Meta tag Defaults
Go to Configuration and click on Metatag.
From the Metatag page, you can configure the default settings used across the whole site, front page, 404/403 and essential content pages.
Noindex on Content Pages
1. If you do not want any content to be indexed, click on Edit next to Content.
2. Scroll down to the Advanced section and check noindex.
3. Save the page and clear the site cache.
4. View the page source and see the noindex meta tag.
NOTE: If you still can’t see it and are sure you configured things correctly, then clear the site cache by going to Configuration, Performance.
Configure Meta Tags for Specific Content Type
The above configuration will apply the noindex to all content pages, i.e., articles and basic pages, which isn’t ideal. This is the type of content you want to be indexed. But what if you wish a single content type not to be indexed, such as “Basic page”.
First, undo the change to the Content meta tag default settings.
1. Click on “Add default meta tags”.
2. Select “Basic page” from the Type drop-down.
3. Click and expand Advanced and check noindex. Then click on Save.
You should see a new configuration below Content called “Content: Basic page”. Now the noindex will only be applied to basic pages.
Control Meta Tags using Meta tags Field
If you want to control meta tags for a specific piece of content, then you can use the Meta tags field with the module.
Let’s add it to the article content type.
1. Go to Structure, “Content types”, and click on “Manage fields” on the Article row.
2. Click on “Add field”, select “Meta tags” from the “Add a new field” drop-down, add a label and click on “Save and continue”.
3. Once the field has been added, go edit an article and you should see the field in the right-hand sidebar.
4. Expand the field and check noindex and then save the form.
Noindex on Taxonomy pages
If you want to add the noindex meta tag to taxonomy pages such as Tags. Then just configure the “Taxonomy term” meta tag default.
Noindex on User pages
Often you do not want user profile pages to be shown in search results, especially if they’re public. To stop profiles from appearing, configure the User configuration.
Noindex on Views page
NOTE: If you want to learn more about Views, then look at “Getting Started with Views”.
It’s common for pages to be built using the Views module and if you want to add noindex to these pages, you need to configure things differently.
1. First we need to install the “Metatag: Views” module. Go to Extend and install it.
2. Edit a view, and you should see the Meta tags section in the middle column.
3. Click on “Using default”, then Advanced and check noindex.
4. Apply the changes and save the view.
Nothing can beat the Metatag module when it comes to controlling meta tags. It’s the de facto way to manage and control meta tags in a Drupal site.
2 thoughts on “How to Add Noindex to Pages using Metatag in Drupal”
Thanks for these tips, Ivan. I’ve always added Rabbit Hole module to do this sort of task of adding noindex. Until now!
Thanks Ivan, really helpful for adding noindex,nofollow pe rpage