GDPR Compliance With Cloudflare & WordPress


About The Author
Cabe Nolan is the founder of WP Cover where he shares his insight into WordPress, development, & entrepreneurship. Outside of WPCover, Cabe continues to run a successful WordPress development firm, Bold City Design as well as a few high profile websites, Arrivala, Two Way Resume, Dock Skipper, and a successful outdoors brand, DolfinPack.







GDPR Compliance With Cloudflare & WordPress

We’ve all heard about the big GDPR phenomenon.  How large companies are spending millions to become compliant and the potential fines that can be thrown out if they are not.

While I’m not going to claim to be an attorney or have much insight into the law, I do have a method that can get you basic compliance fairly quickly.  This particular setup requires:

  • Your sites DNS to be hosted through Cloudflare
  • Your site to be built using PHP (WordPress, Drupal, Joomla, etc.)

If you have both of the above boxes checked off, you’re ready to get started!

Side Note – if your site is not currently run through Cloudflare, it’s easy to switch and 100% free.  Signup for an account at Cloudflare.com and follow their easy onboarding process.

If you’re looking for the quickest implementation, simply copy and paste the below code into your active themes footer.php file:


<?php 
  $country_code = $_SERVER["HTTP_CF_IPCOUNTRY"];
  if (isset($_GET['gdpr']) && $country_code == 'US') {
	$country_code = 'GB';
  }
  $gdprarray = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'GB', 'XX', 'T1'); 
  if(in_array($country_code, $gdprarray)) {
?>
  	
  	<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />
	<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js"></script>
	<script>
	window.addEventListener("load", function(){
	window.cookieconsent.initialise({
	  "palette": {
	    "popup": {
	      "background": "#eb6c44",
	      "text": "#ffffff"
	    },
	    "button": {
	      "background": "#f5d948"
	    }
	  },
	  "theme": "edgeless",
	  "position": "bottom-left"
	})});
	</script>

 
<?php } ?>

Utilizing the above code, you’re only going to see the GDPR cookie notice if you are located within a country that requires GDPR compliance. Therefore, if you are located in the United States you’re not going to see the popup. In order to allow you to test it, simply append ?gdpr=true onto the end of your domain (example: https://www.wpcover.com/?gdpr=true). You’ll see the popup and can confirm your consent. If all looks good and you’re happy with the result you can stop reading here.

If you’d like to further customize the popup, head over to https://cookieconsent.insites.com/download/. This is the open source cookie consent script that we’re using to show the popup. You can customize the color scheme and the behavior using the builder.

Once you’re happy with the look and feel, you’ll want to replace the code in between the conditional PHP statement within the above code. Example:


<?php 
  $country_code = $_SERVER["HTTP_CF_IPCOUNTRY"];
  if (isset($_GET['gdpr']) && $country_code == 'US') {
	$country_code = 'GB';
  }
  $gdprarray = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'GB', 'XX', 'T1'); 
  if(in_array($country_code, $gdprarray)) {
?>
  	
  	<!-- Add Cookie Consent code here -->

 
<?php } ?>

That’s it! You’ve now tackled GDPR compliance in its most basic form.

**Important Note – I am not a lawyer or an attorney. I have no legal knowledge, I’m simply basing this tutorial off my own private reading and comments of others. You should consult with an attorney to ensure you are fully GDPR compliant.


Comments:

  1. Honor Muir says:

    This is the best one

Share Your Thoughts

Leave a Reply

Your email address will not be published.


Related Stuff You Might Like







WordPress News, Tips, & Code Snippets

Join the WP Cover mailing list and get wordpress news, tips, code snippets, security warnings, and more delivered right to your inbox.  We won't flood your inbox, newsletters typically go out every 1-2 weeks unless it involves an important security release.

You have Successfully Subscribed!