PHPackages                             digitoimistodude/air-cookie - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. digitoimistodude/air-cookie

ActiveWordpress-plugin[Utility &amp; Helpers](/categories/utility)

digitoimistodude/air-cookie
===========================

Simple cookie banner and management.

1.3.1(7mo ago)167823[7 issues](https://github.com/digitoimistodude/air-cookie/issues)[2 PRs](https://github.com/digitoimistodude/air-cookie/pulls)GPL-3.0-or-laterPHPCI passing

Since Sep 29Pushed 7mo ago2 watchersCompare

[ Source](https://github.com/digitoimistodude/air-cookie)[ Packagist](https://packagist.org/packages/digitoimistodude/air-cookie)[ Docs](https://github.com/digitoimistodude/air-cookie)[ RSS](/packages/digitoimistodude-air-cookie/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (2)Versions (24)Used By (0)

Air cookie
==========

[](#air-cookie)

[![Packagist](https://camo.githubusercontent.com/a50444ec6b27cadd2fddc110f8f07ffb4b53e58557a90d94a862451550a1c3dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64696769746f696d6973746f647564652f6169722d636f6f6b69652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/digitoimistodude/air-cookie)[![CookieConsent_Version](https://camo.githubusercontent.com/bf9b6ac0a92223b044766a7bfe4daa5f9e9e8ec71fa79561d141452f5eea5d41/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f6f6b6965436f6e73656e7425323056657273696f6e2d322e392e312d79656c6c6f773f7374796c653d666c61742d737175617265)](https://github.com/orestbida/cookieconsent)[![Tested_up_to WordPress_6.4.3](https://camo.githubusercontent.com/f0217a1fa22bc873889b7e9d10df64edadeb6feb83786a9efcd9ac7261e17dc8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5465737465645f75705f746f2d576f726450726573735f362e342e332d626c75652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/f0217a1fa22bc873889b7e9d10df64edadeb6feb83786a9efcd9ac7261e17dc8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5465737465645f75705f746f2d576f726450726573735f362e342e332d626c75652e7376673f7374796c653d666c61742d737175617265)[![Compatible_with PHP_8.3](https://camo.githubusercontent.com/89ed19e0f6bb65aca3fe2fd22f93c7fe4d250dbf93c39d4fb5258bcbcf14e531/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f6d70617469626c655f776974682d5048505f382e332d677265656e2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/89ed19e0f6bb65aca3fe2fd22f93c7fe4d250dbf93c39d4fb5258bcbcf14e531/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f6d70617469626c655f776974682d5048505f382e332d677265656e2e7376673f7374796c653d666c61742d737175617265)[![Build](https://github.com/digitoimistodude/air-cookie/actions/workflows/build.yml/badge.svg)](https://github.com/digitoimistodude/air-cookie/actions/workflows/build.yml)

Air cookie provides simple cookie banner and management.

Uses the [CookieConsent](https://github.com/orestbida/cookieconsent) javascript plugin as a base, making its usage with WordPress easier.

Features
========

[](#features)

- Simple and lightweight cookie banner
- Third party embeds blocking until cookies accepted
- Easy to load scripts and execute custom javascript when cookies are accepted
- Support for multiple different cookie categories
- Polylang support for multilingual websites
- Visitor consent recording
- Cookie categories revision control

Usage
=====

[](#usage)

Link to cookie settings
-----------------------

[](#link-to-cookie-settings)

Remember to add a link into the footer, which allows opening the cookie settings anytime!

```
Cookie settings
```

If you have Polylang installed and active, use

```

```

Cookie categories
-----------------

[](#cookie-categories)

By default, plugin has two cookie categories `necessary`, `functional` and `analytics`. You may add new categories with `air_cookie\categories` filter like shown below.

```
add_filter( 'air_cookie\categories', 'my_add_cookie_category' );
function my_add_cookie_category( $categories ) {
  $categories[] = [
    'key'         => 'ads',
    'enabled'     => false, // it is advised to have categories disabled by default
    'readonly'    => false, // user should have always control over categories
    'title'       => 'Ads',
    'description' => 'This site uses external services to display ads, and they might set some cookies.',
  ];

  return $categories;
}
```

When adding new categories, the function itself is responsile for handling the translations for title and description.

There is also `air_cookie\categories\{category-key}` filter available to change the settings of indivual category.

Loading scripts after cookies have been accepted
------------------------------------------------

[](#loading-scripts-after-cookies-have-been-accepted)

The easiest way to load external script is by altering the `script` tag to be:

```

```

The example above works only, if the script does not require any extra javascript to be executed after the script has been loaded. If you need to execute extra javascript, use the example below.

```
add_action( 'air_cookie_js_analytics', 'my_add_js_for_analytics' );
function my_add_js_for_analytics() {
  ob_start(); ?>
    cc.loadScript( 'https://www.google-analytics.com/analytics.js', function() {
      ga('create', 'UA-XXXXXXXX-Y', 'auto');  //replace UA-XXXXXXXX-Y with your tracking code
      ga('send', 'pageview');
    } );
