Created
November 7, 2023 22:02
-
-
Save rileyrichter/02501557bf414fbda3488dfc4ed4f468 to your computer and use it in GitHub Desktop.
Add a robots no index tag dynamically in Webflow
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
/* | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this | |
software and associated documentation files (the "Software"), to deal in the Software | |
without restriction, including without limitation the rights to use, copy, modify, merge, | |
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | |
to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or | |
substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | |
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | |
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
*/ | |
// Add this between <script></script> tags in the before body section of your page | |
document.addEventListener('DOMContentLoaded', (event) => { | |
// Set this based on your CMS setting | |
// Replace the true with your CMS chip in Webflow | |
const noIndex = true; // true or false based on CMS | |
// Check if noIndex is true | |
if (noIndex) { | |
// Create the meta tag | |
var metaTag = document.createElement('meta'); | |
metaTag.name = "robots"; | |
metaTag.content = "noindex"; | |
// Append the meta tag to the head | |
document.head.appendChild(metaTag); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment