Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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