bassjobsen / wp-defer-loading

Defer loading javascript for WordPress. Without any additional library. Just the way Google ask you to do it.
4 stars 2 forks source link

UK Cookie Consent Plugin #12

Closed bassjobsen closed 11 years ago

bassjobsen commented 11 years ago

The UK Cookie Consent Plugin from http://wordpress.org/plugins/uk-cookie-consent/ don't work with defer loading activate. Also see issue #11

bassjobsen commented 11 years ago

The plugin write a jQuery document ready to source. To fix: create a file uk-cookie-consent/js/cookie-show.js in the plugin folder. cookie-show.js should contain the following code:

        if(!catapultReadCookie("catAccCookies")){//If the cookie has not been set
            jQuery("#catapult-cookie-bar").show();
            jQuery("html").css("margin-top","0");
        }

in uk-cookie-consent.php replace

    function catapult_add_cookie_js() { ?>
        <script type="text/javascript">
            jQuery(document).ready(function(){
                if(!catapultReadCookie("catAccCookies")){//If the cookie has not been set
                    jQuery("#catapult-cookie-bar").show();
                    jQuery("html").css("margin-top","0");
                }
            });
        </script>
    <?php }
    add_action ( 'wp_footer', 'catapult_add_cookie_js' );

with:

    function catapult_add_cookie_js() {
        wp_enqueue_script( 'cookie-show', plugins_url ( 'js/cookie-show.js', __FILE__ ), array( 'jquery' ),'1.6',true);
    }
    add_action( 'wp_enqueue_scripts', 'catapult_add_cookie_js' );