Add a cookie banner to the head of every WordPress page
Add the TermsFeed Privacy Consent cookie banner to WordPress with a header snippet plugin, a child theme, or a wp_head action, because the script needs the head of every page. None of the methods needs a paid WordPress plan, and the plugin directory has no Privacy Consent plugin.
TermsFeed AutoTerms, the free WordPress plugin, does not install Privacy Consent. Its Cookie Consent kit loads TermsFeed Free Cookie Consent, a separate product, so that kit goes off in Step 2.
Setup takes 6 steps and about 15 minutes. Sign in as an Administrator and list the plugins that add tracking or show a consent banner. Copy your snippet from "Install link" on the Overview page in the TermsFeed app. A site with no consent banner yet starts at Create a Consent Banner.
Step 1: Add the Privacy Consent snippet to the head
Choose 1 of the methods, and purge the page cache after it. The header snippet plugin suits most sites, because no theme update or theme change touches it. The child theme suits a classic theme, and the wp_head action suits a site whose code sits in version control.
Method 1: Add the snippet with a header snippet plugin
Use WPCode or any plugin with a site-wide header field.
- Install and activate WPCode from Plugins > Add New Plugin.
- Open Code Snippets > Header & Footer in the WordPress admin.
- Paste the snippet into the Header box.
- Click Save Changes.
Method 2: Paste the snippet into header.php of a child theme
Edit a copy of header.php in a child theme, since the next update of a parent theme deletes any edit to its files. A block theme has no header.php, so use Method 1 or Method 3 on a block theme.
- Activate a child theme of your current theme, and copy
header.phpfrom the parent theme into the child theme folder. - Open Appearance > Theme File Editor and choose the child theme in "Select theme to edit".
- Select Theme Header (
header.php) in the Theme Files list. - Paste the snippet directly before the closing
</head>tag. - Click Update File.
Method 3: Print the snippet from functions.php
Add this wp_head action to the functions.php file of a child theme or to a small site-specific plugin, never to a parent theme. Replace the snippet inside the function with the one the TermsFeed app gives you.
add_action( 'wp_head', function () {
?>
<!-- Privacy Consent by TermsFeed (https://www.termsfeed.com) -->
<script type="text/javascript" src="https://cdn.termsfeedtag.com/plugins/pc/v1/YOUR_TOKEN/plugin.js" async></script>
<!-- End Privacy Consent by TermsFeed (https://www.termsfeed.com) -->
<?php
}, 99 );
A site that sends Google Consent Mode v2 from its own code keeps the defaults above the Google tag and above the snippet. The priority 99 prints the snippet after them. Follow the full order in Install the Script.
Step 2: Turn off other consent plugins and the AutoTerms kits
Deactivate every other consent plugin, such as Complianz, CookieYes, and Cookiebot, in Plugins > Installed Plugins before Privacy Consent goes live. Each consent tool shows its own consent banner and stores its own answer, so a visitor answers twice.
The AutoTerms plugin needs 2 kits turned off. Open TermsFeed > Compliance Kits in the WordPress admin, then click the "Disable" button in the Cookie Consent box and in the Cookie Notice box. Keep the Links to Legal Pages kit and your legal pages, which do not show a consent banner. Manage each kit with WordPress Compliance Kits in TermsFeed AutoTerms.
Step 3: Move WordPress tracking plugins into Privacy Consent vendors
Turn off the code a tracking plugin prints, then add the same tool as a vendor. Privacy Consent holds back only the code in its vendors, so a plugin that keeps printing Google Analytics 4 runs it before the visitor answers. The vendor then counts the same visit a second time.
- Turn off the code output in the plugin. In Site Kit by Google, open Site Kit > Settings > Connected Services > Analytics > Edit and turn off "Place Google Analytics code". For Tag Manager, turn off "Let Site Kit place code on your site" the same way.
- Add the tool as a vendor, from its template where one exists.
- Purge the page cache and open the page source of a page in a private window.
- Confirm that the old code no longer appears in the page source.
Start with Google Analytics 4 where your site runs it. Follow the template steps in Add Google Analytics 4, and find the other tools in Vendor Recipes.
Page builder video widgets take the same treatment. The Elementor Video widget and the Divi Video module print their own YouTube iframe, which loads before consent. Replace each one with an HTML widget or a Code module that holds a replaceable tag, set up with Replaceable Tags in TermsFeed Privacy Consent.
Step 4: Connect the WordPress Consent API for plugins that read it
Send each answer through the WP Consent API plugin, so WordPress plugins that support the API follow it. Privacy Consent sends nothing to WordPress by itself, and a plugin without API support ignores the signal, so that plugin still belongs in a vendor. Map the vendor categories and send each answer with the WordPress Consent API page.
Step 5: Add a Privacy Preferences link to the WordPress footer
Add a footer link that reopens the Privacy Preferences Center, so visitors change their answer from any page. Paste this markup into a Custom HTML block in the footer widget area or footer template part.
<a href="#" id="open_privacy_preferences_element">Privacy Preferences</a>
Keep the id on the link itself instead of a menu item class. WordPress puts a menu item class on the list item, where Privacy Consent does not stop a # link inside it from jumping to the top of the page. Compare this link with the floating button in Reopen Preferences.
Step 6: Purge the caches and add your WordPress hostnames
Purge every page cache after each install change, since a cached page keeps the old head without the snippet. Clear your caching plugin (WP Rocket, LiteSpeed Cache, W3 Total Cache), your hosting cache, and your content delivery network (CDN).
Exclude cdn.termsfeedtag.com from any feature that delays or combines JavaScript. A delayed script holds back the consent banner and every vendor until the visitor first scrolls, clicks, or presses a key. In WP Rocket, add it under "Delay JavaScript execution" > "Excluded JavaScript Files". In LiteSpeed Cache, add it to "JS Deferred / Delayed Excludes" on the Tuning tab of Page Optimization.
List each WordPress hostname that carries the snippet under "Additional domains" on the Settings page of the consent banner, such as a staging hostname. The consent banner loads only on the main website domain and the additional domains, so a staging hostname missing from the list shows none. Follow the steps in Multiple Domains.
How to verify Privacy Consent on WordPress
Purge the cache first, then test in a new private window, where you are logged out and no earlier answer exists. Test step 4 on a plugin tool you moved into an on-accept vendor tag, because a Google template loads its tag before the answer.
- Close every private window, open your site in a new one, open the Chrome DevTools Network tab, filter for
termsfeedtag, and reload.plugin.jsand 2settings.jsonrequests return status 200, and the consent banner shows. - Select the second
settings.jsonrequest and open its Preview tab. Theserviceablefield readstrue. - Select the Console tab. No line holds
[ee]or[ww]. - Type the host of a vendor you moved in the Network filter, such as
hotjar.com, and reload. No request appears before you answer. - Click I Agree. Requests to that host appear with no page reload.
- Type
events.pushin the Network filter. The last request, sent at your click, has status 201. - Click your "Privacy Preferences" link. The Privacy Preferences Center opens.
Test the refusal next. Close every private window, open a new one with the Network tab filtered on the same host, load the WordPress site, and click I Decline. Open a second page, and no request to that host appears. Run the remaining checks with Verify Your Installation.
Common mistakes with Privacy Consent on WordPress
- The snippet sits in one post or page. A Custom HTML block inside the content loads Privacy Consent on that page only. Use a site-wide method from Step 1.
- The parent theme holds the edit. A theme update replaces
header.phpand removes the snippet with no warning. Move the snippet to a child theme or a header snippet plugin. - A plugin still prints the tracking code. Site Kit or a tag manager plugin runs Google Analytics 4 before consent. Turn off its code output in the plugin settings.
- The AutoTerms Cookie Consent kit stays on. Visitors see 2 consent banners, and an answer in the kit does nothing in Privacy Consent. Click the "Disable" button in the Cookie Consent box.
- A cached page hides the change. The page cache serves the old head until you purge it, so the source of a logged-out page lacks
plugin.js.