How to add cookie consent to WordPress
You do not need a heavy plugin to put a GDPR cookie consent banner on a WordPress site. Here are three clean ways to add one, how to gate your analytics and pixels, and the caching gotcha to watch for.
Three ways to add the banner
Option 1: a code snippets plugin
The simplest route. Install a snippets plugin such as WPCode or Code Snippets, create a snippet set to run in the site footer, and paste the banner script. This keeps the code out of your theme so it survives theme updates.
Option 2: your theme's custom code area
Many themes and page builders have a "Footer code" or "Before </body>" field under theme or customizer settings. Paste the script there.
Option 3: a footer hook in a child theme
If you prefer code, add it to your child theme's functions.php:
add_action('wp_footer', function () { ?>
<script>
window.TheCookieShooterConfig = { siteName: "My Site", lang: "auto" };
</script>
<script src="/wp-content/uploads/the-cookie-shooter.js"></script>
<?php });
Upload the JavaScript file to your media or a folder under
wp-content, and point the src at it.
Gate your analytics and pixels
WordPress sites usually load trackers through plugins (a Google Analytics plugin, a Meta pixel plugin, and so on). For consent to be valid, those must not fire before the visitor accepts. The cleanest approach is to route all tags through Google Tag Manager and trigger them on consent, rather than letting each plugin inject its own script. If you add tags by hand, tag them so they wait:
<script type="text/plain" data-consent="analytics"
src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
Caching
WordPress caching plugins (WP Rocket, LiteSpeed, W3 Total Cache) cache the HTML page, but the banner runs in the browser, so caching is fine. After you install it, purge the cache and test in a private window so you see the first-visit experience.
A WordPress-friendly banner
One script, no plugin bloat, no tracking. The Cookie Shooter drops into any WordPress theme and remembers each visitor's choice.
Get The Cookie Shooter See the live demoFrequently asked questions
Do I need a plugin for cookie consent on WordPress?
No. A lightweight script via a footer hook or a snippets plugin works. A dedicated consent plugin is an option too, but many are heavy.
Will a caching plugin break the banner?
No. It runs client-side, so caching the page is fine. Purge the cache and test in a private window after installing.