WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] UK Cookie Consent - avoid flashes of cookie bar (1 post)

  1. chrisHe
    Member
    Posted 8 months ago #

    Hi, this hack relates to plugin "UK Cookie Consent" v1.4.2 (current version), may also work with earlier versions, but I have not tested that.

    Issue: The "Cookie bar" is initially visible on web pages, until the presence of the CatAccCookie is verified on the client machine, when it is then hidden. The effect is that for users that HAVE accepted cookies, the bar may be shown for a short period, which is distracting.
    This hack simply reverses the logic, so that the bar is hidden by default, and only shown if the user coookie is NOT detected.

    Changes affect only the plugin file uk-cookie-consent.php
    1. Change the css style of #catapult-cookie-bar so it is initially hidden:
    Add a new line 247 to hide display, as below

    245	background-color: ' . $bg_colour . ';
    246	text-align:left;
    247	display:none;	// add this for "reverse logic"
    }

    change the jQuery function at lines 270-273 to reverse the logic (note the exclamation mark in revised line 270, which means 'NOT')

    Remove these 4 lines from line 270, or comment out as shown:

    270	// if(catapultReadCookie("catAccCookies")){//If the cookie has been set
    271	// jQuery("#catapult-cookie-bar").hide();
    272	// jQuery("html").css("margin-top","0");
    273 // }

    Replace with these 4 lines:

    270	if(!catapultReadCookie("catAccCookies")){	// If the cookie has NOT been set
    271	jQuery("html").css("margin-top","0");
    272	jQuery("#catapult-cookie-bar").show(); // needed, so show it
    273  }

    When testing, remember to first delete the "CatAccCookie" from your browser.

    Ok, that's it.
    An additional OPTIONAL change is to load both the css and js in footer, not head - this makes only a marginal difference to load speed:
    Line 266 add_action ( 'wp_footer', 'catapult_add_cookie_css' ); //was wp_head
    Line 283 add_action ( 'wp_footer', 'catapult_add_cookie_js' ); //was wp_head

Reply

You must log in to post.

About this Topic