Add the generator code to every page of your site
Installing TermsFeed Free Cookie Consent takes 4 steps, about 15 minutes: create the code, keep the preferences link, tag your scripts, and confirm optional ones wait for consent by default. Without tagged scripts, the consent banner shows but every script still runs before consent.
The code is the same on every platform, and only the place you paste it changes. On a site builder, a content management system, or a static site generator, follow the guide for your platform.
Where the code goes on each platform
Paste the code into the site-wide slot of your platform, so it prints on every page.
| Platform | Where the code goes | Paid plan for site-wide code |
|---|---|---|
| Shopify | layout/theme.liquid in the theme code editor |
A plan with the theme code editor |
| WordPress | The footer box of a code plugin, or wp_footer in a child theme |
No on self-hosted WordPress; WordPress.com needs a plan that allows plugins |
| Wix | Settings > Custom Code, Body - end, all pages | Yes, a Premium plan with a connected domain |
| Squarespace | Code Injection > Footer | Yes, Core, Plus, or Advanced |
| Webflow | Site settings > Custom code > Footer code | Yes, a Site plan or a paid Workspace plan |
| Static site generators | The base layout of Hugo, Jekyll, Eleventy, Gatsby, or Docusaurus | No |
| Other platforms | The site-wide code slot of Drupal, Ghost, Framer, HubSpot CMS, BigCommerce, or Blogger | Depends on the platform |
What you need before you install the code
You need write access to your site template and a list of the third-party scripts it loads, such as Google Analytics 4, the Meta Pixel, or a chat widget. The checks use a desktop browser and name the tabs of Chrome DevTools. Firefox and Safari show cookies on a tab named Storage instead of Application.
Step 1: Create the code and paste it before the closing body tag
Create the code in the TermsFeed generator at termsfeed.com/cookie-consent, then paste it into your template right before </body>. The generator asks for the consent type, your website name, the layout, the color palette, the language, and the link to your Privacy Policy. Keep express consent for any site with visitors from the European Union, the United Kingdom, or Switzerland.
The generator writes the script address without https:. The example code adds https:, and the address loads the same file with or without it.
<!-- Cookie Consent by TermsFeed https://www.TermsFeed.com -->
<script type="text/javascript" src="https://www.termsfeed.com/public/cookie-consent/4.2.0/cookie-consent.js" charset="UTF-8"></script>
<script type="text/javascript" charset="UTF-8">
document.addEventListener('DOMContentLoaded', function () {
cookieconsent.run({"notice_banner_type":"headline","consent_type":"express","palette":"dark","language":"en","page_load_consent_levels":["strictly-necessary"],"notice_banner_reject_button_hide":false,"preferences_center_close_button_hide":false,"page_refresh_confirmation_buttons":false,"website_name":"Example Store"});
});
</script>
<noscript>Free cookie consent management tool by <a href="https://www.termsfeed.com/">TermsFeed Generator</a></noscript>
<!-- End Cookie Consent by TermsFeed https://www.TermsFeed.com -->
<!-- Below is the link that users can use to open Preferences Center to change their preferences. Do not modify the ID parameter. Place it where appropriate, style it as needed. -->
<a href="#" id="open_preferences_center">Update cookies preferences</a>
Keep both scripts in place, because Cookie Consent stops working when one of the 2 scripts is missing, and keep the <noscript> line. Keep charset="UTF-8" on the first script tag. www.termsfeed.com sends the script as UTF-8 too, so the translated texts render correctly whatever the encoding of your page. The inline script passes an options object to cookieconsent.run(). Every setting of Cookie Consent is a key in this object.
The generator writes page_load_consent_levels as ["strictly-necessary"] for express consent and as all 4 categories for implied consent. It writes "language" with the language you chose, and a set language overrides the browser language. It writes "palette" with the palette you chose, while Cookie Consent without that option uses the light palette. Change any option with Configure Your Cookie Banner.
Step 2: Keep a link that reopens the Preferences Center
Keep the "Update cookies preferences" link on every page, so visitors change or withdraw their consent as easily as they gave it. The link works through its id, open_preferences_center: a click on any element with that id opens the Preferences Center. Move, reword, and style the link, but keep the id.
The link works on content added after the page loads too, because Cookie Consent checks the id on every click. Open the Preferences Center from a menu item or a button, or match a class instead of the id, with Add a Cookie Settings Link.
Step 3: Tag your third-party scripts
Change each third-party script on your list so it waits for consent by default: set type="text/plain" and add data-cookie-consent with its category. Replace scripts your platform or plugins add with tagged copies where the platform allows it.
Keep the async of an external script that has one, unless inline code after it uses the library.
<script type="text/plain" data-cookie-consent="tracking" async src="https://analytics.example.com/script.js"></script>
Tag inline scripts the same way. Choose the category for each script with The 4 Cookie Categories.
Google Analytics 4 takes the same 2 attributes for basic consent mode, or loads untagged for advanced consent mode. Copy the tagged Google tag from the Google Analytics 4 recipe, or send the signals with Set Up Google Consent Mode v2.
Step 4: Confirm that optional scripts you tag wait for consent
Publish the changed template and clear any page cache first. In express consent with page_load_consent_levels at its default, confirm that no request of an optional tagged script leaves the browser before you click the "I agree" button. A private window does not hold an earlier answer once every other private window is closed, so the consent banner shows.
Run the check in Chrome with one tagged script from your list. An untagged Google tag under Consent Mode sends collect requests with gcs=G100 before the answer by design, so leave it out of this check.
- Close every private window, open a new one, open DevTools, and select the Network tab.
- Type the host of the tagged script in the Network filter box, then load your site.
- Confirm that the consent banner shows and that the Network tab does not list any request to that host.
- Click the "I agree" button, and confirm that requests to that host appear with no page reload.
Where the Cookie Consent code goes and why
The Cookie Consent code works anywhere in the page, above or below the scripts you tag. The generated code calls run() when the browser has read the whole page, on DOMContentLoaded, so Cookie Consent finds every tagged script in your HTML. With the code right before </body>, the page content renders first. The generator text says to place it right after the opening <body> tag, which works for the tagged scripts as well.
A tagged script that your code adds after cookieconsent.run() starts never runs, because Cookie Consent reads the tagged scripts once, when it starts. Load a script that a single-page app adds on a later route from a callback, with the pattern in Single-Page Apps and Frameworks.
Keep a single copy of the code on each page. A second copy of the code or a second cookieconsent.run() call on the same page does nothing, and the first Cookie Consent keeps running with its own options. A code box on a single page covers that page only.
Install guides for site builders and content management systems
| Guide | What it covers |
|---|---|
| Shopify | theme.liquid, the Shopify consent banner, and the Shopify Customer Privacy API |
| WordPress | The footer code, Site Kit and other plugins, script_loader_tag, and page speed plugins |
| Wix | Custom Code, Marketing Integrations, and the Wix consent banner |
| Squarespace | Footer Code Injection, the Squarespace consent banner, and the built-in analytics field |
| Webflow | Footer code, the built-in analytics integration, and Webflow Analyze |
Install guide for static site generators
Add the code once to the base layout.
| Guide | What it covers |
|---|---|
| Static Site | Hugo, Jekyll, Eleventy, Gatsby, and Docusaurus, the theme analytics to turn off, and preview hostnames |
Install guide for other platforms
| Guide | What it covers |
|---|---|
| Other Platforms | Drupal, Ghost, Framer, BigCommerce, HubSpot CMS, Blogger, and platforms with no site-wide code slot |
Install Cookie Consent in a JavaScript framework
A JavaScript framework takes the code in its HTML shell or root layout, and cookieconsent.run() runs once per page load. Set up React, Next.js, Vue, Nuxt, Angular, SvelteKit, Astro, or Turbo Drive, with its route changes and page views, using Single-Page Apps and Frameworks.
What to do after installing Cookie Consent
Step 4 checks one tagged script. Close every private window and, in a new one, run the full check of every part of the install with Check That Your Cookie Banner Works. Change the layout, colors, or language of the consent banner with Configure Your Cookie Banner.