WordPress implementation

Implementing the cookiebanner

You can use the offical wordpress plugin to implement the cookiebanner or you could implement the cookiebanner manually.

Download, install and activate the plugin.

cookiebot-plugin

Once activated navigate to the settings tab of the plugin and insert your Cookiebot ID which you can find in the cookiebot manager. It looks like this: data-cbid="00000000-0000-0000-0000-000000000000".

When using advanced functionalities please read the official plugin page.

Manual implementation

Add your personal Cookiebot script for the consent dialog. Your script is available in the Cookiebot manager under ‘Your scripts’. Please choose whether you want to use automatic blocking mode or manual blocking mode. Add your preferred script to the WordPress theme file “header.php” inside the <head>-tag and before the wp_head() call, e.g. (marked in bold):
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<title><?php wp_title(); ?></title>
<link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>" type="text/css" media="screen" />
<script id="CookieConsent" src="https://consent.cookiebot.com/uc.js" data-cbid="00000000-0000-0000-0000-000000000000" type="text/javascript" async></script>
<?php wp_head(); ?>
</head>

* Please note that this example doesn’t use automatic cookie blocking mode

When saved, the cookie consent banner will display on your website. If you have used Automatic Cookie Blocking Mode you may skip ahead to Showing your cookie declaration in full on a separate WordPress page or post.

Manually implementing prior consent on plugins:

To hold back plugin-cookies until the visitor has consented, script tags within the plugin must be marked up with the tag attribute “data-cookieconsent”. The value of this attribute must be set to one or more of the following values (comma-separated) which must reflect the type(s) of cookies being set by the script tag: preferences, statistics, marketing. Finally the “type”-attribute of the script tag must be set or changed to “text/plain” (highlighted in bold).

Example:

<script type="text/plain" data-cookieconsent="marketing" src="http://s7.addthis.com/js/250/addthis_widget.js"></script>

In WordPress, script tags may also load from plugins with the function wp_enqueue_script. In that case you can make the necessary modifications to the script tag using the filter script_loader_tag.

PHP plugin example:

wp_enqueue_script('addthis_widget.js', $script);

add_filter( 'script_loader_tag', function ( $tag, $handle ) {
    if ( 'addthis_widget.js' !== $handle )
        return $tag;
    $tagstring = str_replace( 'text/javascript', 'text/plain', $tag );
    $tagstring = str_replace( ' src', ' data-cookieconsent="marketing" src', $tagstring );
    return $tagstring;
}, 10, 2 );

Showing your cookie declaration in full on a separate WordPress page or post:

If you want to show your cookie declaration in full on a seperate page or as part of your privacy policy, embed your cookie declaration script as described below.

In the content editor for the page or post where you want to show your cookie declaration in full, switch to text view mode and paste the script code where you want the declaration to show, e.g.:

<script id="CookiePolicy" src="https://consent.cookiebot.com/00000000-0000-0000-0000-000000000000/cd.js" type="text/javascript" async></script>

Was this article helpful?
2.5 out of 5 stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 100%
1 Stars 0%
How can we improve this article?
Inhoud