WordPress Integration
Complete guide for adding CookieFast to your WordPress website using plugins or manual code.
Method 1: Using a Plugin (Recommended)
Step 1: Install Header/Footer Plugin
Install one of these free plugins:
- Insert Headers and Footers (Most popular)
- WPCode (Recommended for advanced users)
- Head, Footer and Post Injections
Installation:
- Go to Dashboard → Plugins → Add New
- Search for "Insert Headers and Footers"
- Click Install Now, then Activate
Step 2: Add CookieFast Script
- Go to Settings → Insert Headers and Footers
- In the Scripts in Header section, paste:
<scriptasyncsrc="https://cdn.cookiefa.st/cookiefast.js"data-api-key="your-api-key-here"></script>
- Replace
your-api-key-herewith your actual API key - Click Save
Step 3: Clear Cache
If using a caching plugin (WP Rocket, W3 Total Cache, etc.):
- Go to your cache plugin settings
- Click Clear Cache or Purge All
- Visit your site in incognito mode to verify
Method 2: Manual Theme Integration
Edit Theme Header
Create a child theme before editing theme files to prevent updates from overwriting your changes.
- Go to Appearance → Theme File Editor
- Select your theme from the dropdown
- Click on
header.php(orfunctions.phpfor safer approach) - Add the script
Option A: In header.php
Find the </head> closing tag and add before it:
<head><?php wp_head(); ?><!-- CookieFast --><scriptasyncsrc="https://cdn.cookiefa.st/cookiefast.js"data-api-key="your-api-key-here"></script></head>
Option B: In functions.php (Safer)
Add to the end of functions.php:
function add_cookiefast_script() {?><scriptasyncsrc="https://cdn.cookiefa.st/cookiefast.js"data-api-key="<?php echo esc_attr(get_option('cookiefast_api_key')); ?>"></script><?php}add_action('wp_head', 'add_cookiefast_script');
Cookie Settings Link
Add a cookie settings link to your footer, menu, or anywhere:
In Menus
- Go to Appearance → Menus
- Click Custom Links
- Add:
- URL:
#cookiefast - Link Text:
Cookie Settings
- URL:
- Add to menu and save
In Footer Widget
- Go to Appearance → Widgets
- Add HTML widget to footer
- Paste:
<button id="cookiefast-banner-trigger" style="background: none; border: none; color: #0073aa; text-decoration: underline; cursor: pointer;">Cookie Settings</button>
In Text/Page Content
Use the HTML block in Gutenberg:
<span id="cookiefast-banner-trigger">Cookie Settings</span>
Popular Page Builders
Elementor
- Edit your page/template with Elementor
- Add HTML widget
- Paste:
<scriptasyncsrc="https://cdn.cookiefa.st/cookiefast.js"data-api-key="your-api-key-here"></script>
- Place in header template for site-wide coverage
Divi
- Go to Divi → Theme Builder
- Edit your global header
- Add Code module
- Paste script and save
WPBakery
- Edit page with WPBakery
- Add Raw HTML element
- Paste script
- For global: edit in Templates → Header
WooCommerce Integration
CookieFast works automatically with WooCommerce. For analytics:
Google Analytics for WooCommerce
Configure in CookieFast dashboard instead of WooCommerce:
- Go to CookieFast Dashboard → Your Property
- Add script in Analytics category:
// Google Analytics 4 for WooCommerce(function() {var script = document.createElement('script');script.async = true;script.src = 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX';document.head.appendChild(script);window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'G-XXXXXXXXXX');})();
- Disable Google Analytics in WooCommerce settings to avoid conflicts
Multisite Networks
Network-Wide Activation
Add to wp-config.php (above "That's all"):
define('COOKIEFAST_API_KEY', 'your-api-key-here');
In theme's functions.php:
function add_cookiefast_multisite() {if (defined('COOKIEFAST_API_KEY')) {?><scriptasyncsrc="https://cdn.cookiefa.st/cookiefast.js"data-api-key="<?php echo esc_attr(COOKIEFAST_API_KEY); ?>"></script><?php}}add_action('wp_head', 'add_cookiefast_multisite');
Per-Site Keys
Use different API keys per site:
function add_cookiefast_per_site() {$site_id = get_current_blog_id();$api_keys = array(1 => 'site-1-api-key',2 => 'site-2-api-key',3 => 'site-3-api-key',);if (isset($api_keys[$site_id])) {?><scriptasyncsrc="https://cdn.cookiefa.st/cookiefast.js"data-api-key="<?php echo esc_attr($api_keys[$site_id]); ?>"></script><?php}}add_action('wp_head', 'add_cookiefast_per_site');
Common Issues
Script Not Loading
- Clear all caches: Browser cache, WordPress cache plugin, CDN cache
- Check theme: Ensure theme has
<?php wp_head(); ?>in header - Plugin conflicts: Deactivate plugins one by one to find conflicts
- View source: Right-click → View Page Source, search for "cookiefast"
Banner Shows on Admin Pages
The script should only load on front-end. If showing on admin:
function add_cookiefast_frontend_only() {if (!is_admin()) {?><scriptasyncsrc="https://cdn.cookiefa.st/cookiefast.js"data-api-key="your-api-key-here"></script><?php}}add_action('wp_head', 'add_cookiefast_frontend_only');
Cache Plugin Issues
WP Rocket:
- Go to Settings → WP Rocket
- File Optimization tab
- Add to "JavaScript Files to Exclude from Defer":
cookiefast.js
W3 Total Cache:
- Performance → Minify
- Add to "Never minify the following JS files":
cdn.cookiefa.st/cookiefast.js
Performance Optimization
- ✅ CookieFast loads asynchronously (doesn't block rendering)
- ✅ Served from global CDN
- ✅ Auto-cached by browsers
- ✅ ~50KB minified
PageSpeed Tips
If CookieFast affects PageSpeed score:
// Preconnect to CDNfunction cookiefast_preconnect() {echo '<link rel="preconnect" href="https://cdn.cookiefa.st">';}add_action('wp_head', 'cookiefast_preconnect', 1);
Next Steps
- Configure Banner - Customize colors and text
- Add Analytics Scripts - Configure tracking
- View Consent Data - Monitor compliance
