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.
- Edit the Template your pages use.
- Somewhere within the
<head>tags, add the following and save:
<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.
- Edit the Metadata Set your pages use.
- Switch to the Custom Fields tab.
- 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
- Under Configuration, switch to the XML tab, paste the following, and click Submit:
<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.
#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:

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