WordPress and buddypress programming

Setup Cookie consent code in 2 minute without plugin

Viewing 0 reply threads
  • Author
    Posts
    • #1867
      michael mc
      Keymaster
      @michael
      <script>
      //<![CDATA[
      var _tppCookieMessage = 'This website uses cookies to improve your experience. We\'ll assume you\'re ok with this, but you can opt-out if you wish.';
      var _tppButtonTitle = 'Accept';
      var _tppMoreInfoPageLink = 'YOUR_PRIVACYPAGE_OR_COOKIEPAGE_LINK';
      var _tppCookieForDays = 30;
      
      if (!getCookie("cookieConsentAccepted")) {
       var cookHtml = '<div id="cookie-law-info-bar" class="tpp__cook_msg"><span>'+_tppCookieMessage+'<hr/><button id="acceptCookie">'+_tppButtonTitle+'</button>&nbsp;&nbsp;&nbsp;<a target="_blank" href="'+_tppMoreInfoPageLink+'">Read More</a></span></div>';
       var _cdiv=document.createElement('div');
       _cdiv.id='_cookieMessageDiv';
       document.body.appendChild(_cdiv);
       var _divTag=document.getElementById("_cookieMessageDiv");
       _divTag.innerHTML+=cookHtml;
      }
      
      function setCookie(e, o, t) {
       var n = new Date;
       n.setTime(n.getTime() + 24 * t * 60 * 60 * 1e3);
       var i = "expires=" + n.toUTCString();
       document.cookie = e + "=" + o + ";path=/; " + i
      }
      
      function getCookie(e) {
       for (var o = e + "=", t = document.cookie.split(";"), n = 0; n < t.length; n++) {
        for (var i = t[n]; " " == i.charAt(0);) i = i.substring(1);
         if (0 == i.indexOf(o)) return i.substring(o.length, i.length)
       }
       return ""
      }
      
      window.onload = function() {
       var e = document.getElementById("acceptCookie");
       e && e.addEventListener("click", function() {
        setCookie("cookieConsentAccepted", "YES", _tppCookieForDays), 
        document.getElementById("cookie-law-info-bar").remove()
       })
      };
      //]]>
      </script>

      css code
      /** tpp consent **/
      .tpp__cook_msg{display:block;background-color:#ccc;color:#000;font-family:inherit;bottom:0;position:fixed;padding:10px 5px 30px 5px;text-align:center;width:100%;z-index:9999999;border-top:1px solid #aaa;opacity:0.9;}
      .tpp__cook_msg hr{border-bottom:1px solid #e5e5e5;margin:10px;border:none;border-bottom:1px solid #c1c1c1;}
      .tpp__cook_msg a{font-weight:700;text-decoration:none;color:#3946e2}
      .tpp__cook_msg #acceptCookie{background-color:#29861e;color:#fff;border:2px solid #4b9c37;border-radius:5px;padding:5px 10px;font-size:15px;}
      /** tpp consent **/

    • Change YOUR_PRIVACYPAGE_OR_COOKIEPAGE_LINK text with your related page url.
      For example: var _tppMoreInfoPageLink = ‘http://example.com/privacy&#8217;;
      Open your blog admin and add new HTML widget.
      Copy JavaScript code from this page, past in HTML widget and save.
      How to setup Cookie consent CSS code?
      For WordPress open Appearance > Customize > Additional CSS option.
      For Blogger open Theme > Customize > Advanced > Add CSS option.
      Copy CSS code from this page, past in CSS option and save.
Viewing 0 reply threads
  • You must be logged in to reply to this topic.