Skip to main content

Configuring a robots meta tag

This article walks through a sample setup that outputs a robots meta tag in the source of one or more pages, letting you tell search engines whether to index a page and whether to crawl its links.

Worked example

This is one of many ways to approach this. Adapt any step to your own setup.

Template setup

First, include a region in your Template where the resulting <meta> tag will be placed.

  1. Edit the Template your pages use.
  2. Somewhere within the <head> tags, add the following and save:
HTML
<system-region name="ROBOTS"/>

Metadata Set setup

Add a field to your Metadata Set so page editors can select how a page should be treated.

  1. Edit the Metadata Set your pages use.
  2. Switch to the Custom Fields tab.
  3. Add a new Checkbox field with these values:
    • Name: search-engine-options
    • Field Label: Search engine behavior
    • Help Text: Specify how this page should be treated by search engines in terms of appearing in search results and link crawling
  4. Under Configuration, switch to the XML tab, paste the following, and click Submit:
XML
<checkbox>
  <item label="Prevent indexing of this page">noindex</item>
  <item label="Prevent crawling of links in this page">nofollow</item>
</checkbox>

Format setup

Write a Velocity Format that checks which options were selected and outputs the matching tag.

Velocity
#set ($searchEngineOptions = $currentPage.metadata.getDynamicField("search-engine-options"))
#set ($robotsContent = $_DisplayTool.list($_ListTool.toList($searchEngineOptions.values), ","))
#if (!$_PropertyTool.isEmpty($robotsContent))
<meta content="${robotsContent}" name="robots"/>
#end

Attach the Format

Attach the Format to the ROBOTS region. You can do this at the Template, Configuration, or individual Page level, depending on which pages should inherit the setup. Attaching at the Template level is most common, so every page using that Template has the region available.

End result

Editors see the options when editing a page:

Checkbox options for the robots tag as they appear when editing a page

If no options are selected, no <meta> tag is added. If one or both are selected, the tag is included with the matching values. With both selected, the output is:

HTML
<meta content="nofollow,noindex" name="robots"/>

"Indexing" here refers to search engine behavior. Don't confuse it with an asset's Include when indexing option, which is specific to the CMS and has no effect on search engines.