Created
April 22, 2021 13:21
-
-
Save dwsmart/b2fc127326378df9b11104bb6529f243 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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