Implement Google Cookie code – how?

  • Fritsjof



    Today I decided to finally implement the cookie bar so EU visitors can agree on the cookies that are placed on their machines while using my website.

    Google opened up a nice website with code snippets so I wen on using it:

    The website reads:

    In order to implement this JavaScript solution you will need to copy and paste this code into the <body> of your page. You will also need to download the cookiechoices.js file and upload that file to your server directory.

    So I put this code on the footer.php file of my WP sites:

    <!-- You should make sure that the file cookiechoices.js is available
    and accessible from the root directory of your site. -->
    <script src="/cookiechoices.js"></script>
    document.addEventListener('DOMContentLoaded', function(event) {
    cookieChoices.showCookieConsentBar('Your message for visitors here',
    'close message', 'learn more', '');

    Before the </body> tag, the put the .js file in the root of my sites using FTP, then cleared all W3 caches and voila! Working like a charm.

    Then I had to do it for my WP sites that use the Graphene them, and there I ran into trouble: the cookie-bar is not showing up. I tried the code in the footer, in the header, cleared caches, put the .js file on multiple places to be sure it’s there.


    Does anyone have any idea where I should place the code in order to get it working?

    Thanks a bunch!


    Kenneth John Odle


    You are only obligated to show the cookie consent if your server is located in the EU. I take it your is?

    If so, there are a number of plugins which will handle this for you much easier than the messy way listed above, which is not for WordPress sites.



    Kenneth, thanks for your reply.

    Yes, both the server and the intended audience for my websites are located in the EU, therefore the cookie-annoyance is mandatory.

    Any plugins you can recommend for implementing a cookie-wall, one that works smoothly with the Graphene theme specifically?

    Thanks again for your help.


    Kenneth John Odle


    I don’t use any, but there is a list in the plugin repository here:


    Kenneth John Odle


    I don’t use any, but there is a list in the plugin repository here:

Viewing 5 posts - 1 through 5 (of 5 total)

  • You must be logged in to reply to this topic.