CookieFast

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:

  1. Go to DashboardPluginsAdd New
  2. Search for "Insert Headers and Footers"
  3. Click Install Now, then Activate

Step 2: Add CookieFast Script

  1. Go to SettingsInsert Headers and Footers
  2. In the Scripts in Header section, paste:
<script
async
src="https://cdn.cookiefa.st/cookiefast.js"
data-api-key="your-api-key-here"
></script>
  1. Replace your-api-key-here with your actual API key
  2. Click Save

Step 3: Clear Cache

If using a caching plugin (WP Rocket, W3 Total Cache, etc.):

  1. Go to your cache plugin settings
  2. Click Clear Cache or Purge All
  3. 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.

  1. Go to AppearanceTheme File Editor
  2. Select your theme from the dropdown
  3. Click on header.php (or functions.php for safer approach)
  4. Add the script

Option A: In header.php

Find the </head> closing tag and add before it:

<head>
<?php wp_head(); ?>
<!-- CookieFast -->
<script
async
src="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() {
?>
<script
async
src="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

  1. Go to AppearanceMenus
  2. Click Custom Links
  3. Add:
    • URL: #cookiefast
    • Link Text: Cookie Settings
  4. Add to menu and save

In Footer Widget

  1. Go to AppearanceWidgets
  2. Add HTML widget to footer
  3. 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

  1. Edit your page/template with Elementor
  2. Add HTML widget
  3. Paste:
<script
async
src="https://cdn.cookiefa.st/cookiefast.js"
data-api-key="your-api-key-here"
></script>
  1. Place in header template for site-wide coverage

Divi

  1. Go to DiviTheme Builder
  2. Edit your global header
  3. Add Code module
  4. Paste script and save

WPBakery

  1. Edit page with WPBakery
  2. Add Raw HTML element
  3. Paste script
  4. For global: edit in TemplatesHeader

WooCommerce Integration

CookieFast works automatically with WooCommerce. For analytics:

Google Analytics for WooCommerce

Configure in CookieFast dashboard instead of WooCommerce:

  1. Go to CookieFast DashboardYour Property
  2. 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');
})();
  1. 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')) {
?>
<script
async
src="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])) {
?>
<script
async
src="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

  1. Clear all caches: Browser cache, WordPress cache plugin, CDN cache
  2. Check theme: Ensure theme has <?php wp_head(); ?> in header
  3. Plugin conflicts: Deactivate plugins one by one to find conflicts
  4. 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()) {
?>
<script
async
src="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:

  1. Go to SettingsWP Rocket
  2. File Optimization tab
  3. Add to "JavaScript Files to Exclude from Defer": cookiefast.js

W3 Total Cache:

  1. PerformanceMinify
  2. Add to "Never minify the following JS files": cdn.cookiefa.st/cookiefast.js

Performance Optimization

  1. ✅ CookieFast loads asynchronously (doesn't block rendering)
  2. ✅ Served from global CDN
  3. ✅ Auto-cached by browsers
  4. ✅ ~50KB minified

PageSpeed Tips

If CookieFast affects PageSpeed score:

// Preconnect to CDN
function cookiefast_preconnect() {
echo '<link rel="preconnect" href="https://cdn.cookiefa.st">';
}
add_action('wp_head', 'cookiefast_preconnect', 1);

Next Steps