Skip to content

Instantly share code, notes, and snippets.

@dwsmart
Created April 22, 2021 13:21
Show Gist options
  • Save dwsmart/b2fc127326378df9b11104bb6529f243 to your computer and use it in GitHub Desktop.
Save dwsmart/b2fc127326378df9b11104bb6529f243 to your computer and use it in GitHub Desktop.
// update existing robots tag if one is there
const oldRobots = document.querySelector("[name='robots']");
if (oldRobots) {
oldRobots.content = "noindex";
} else {
// add one if none existed
const newRobots = document.createElement('meta');
newRobots.name = "robots";
newRobots.content = "noindex";
document.getElementsByTagName('head')[0].prepend(newRobots);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment