This tutorial provides the steps to display a fixed cookie consent bar that can be dismissed by your site visitors at the bottom of your site.

Step 1

Go to, configure the cookie consent bar to your liking and you should see the generated code.

In this example, we shall go with the default one.

Step 2

Install and activate Code Snippets plugin.

Go to Snippets > Add New.

Title: Cookie Consent


add_action( 'wp_head', 'custom_cookie_consent' );
 * Add Cookie Consent bar.
 * @link Code generated from here.
function custom_cookie_consent() { ?>

    <link rel="stylesheet" type="text/css" href="//" />
    <script src="//"></script>
    window.addEventListener("load", function(){
      "palette": {
        "popup": {
          "background": "#000"
        "button": {
          "background": "#f1d600"

<?php }

Replace the code above in between function custom_cookie_consent() { ?> and <?php } with the code generated in the earlier step.

Set it to run only on the front-end.

Save and activate.

Need help implementing a tutorial in your site or want to hire me for custom work?


Find the article helpful and wish to donate?



For adding code blocks wrap the code in three backticks. Markdown should work.
Provide a URL of your site/webpage if something is not working.

6 comments on “How to set up a Cookie Consent bar in WordPress”

  1. Isn’t this bad for performance?

    GTMetrix shows two files which add 0,6 seconds to loading time:
    293.7ms + 294.1ms

    Could this be done with Oxygens own modal for better performance?

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: