• Resolved tcress101

    (@tcress101)


    I’ve been playing with this all night and even tried the very latest update from tonight (1.0.9?)

    I’m trying to add code snippets for analytics software and ad management software into the boxes (under 3rd party cookies and additional cookies) that say: “The below script will be added to the page HEAD section if user enables this cookie” but nothing is inserted on the page once a visitor accepts the cookies. I double check View Source on the page and nothing’s been added. I’ve cleared web cache. Nothing helps.

    I’m just copying & pasting the code directly from the programs I’m using, should I be formatting the code differently?

    For example:

    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXX"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    gtag('config', 'UA-XXXXX');
    </script>
Viewing 15 replies - 1 through 15 (of 18 total)
  • I’m having the same problem on all my websites using this plugin, it doesn’t matter if the theme is Avada or Divi the code simply doesn’t get printed on the website.

    I think it has something to do with the new version of WordPress which have been updated to v. 4.9.6.

    If you want a quick fix and know a little about PHP you can use below code in the functions.php file:

    if(isset($_COOKIE['moove_gdpr_popup']) && $_COOKIE['moove_gdpr_popup']=='{\"strict\":\"1\",\"thirdparty\":\"1\",\"advanced\":\"1\"}') {
    
    function thirdparty_script() { ?>
    <script>Insert your script here
    </script>
    
    <?php
    }
    add_action( 'wp_head', 'thirdparty_script' );
    }
    
    else {
        
    }
    • This reply was modified 6 years, 6 months ago by mikkelhusum.

    Shouldn’t the development team update that problem fast enough since it’s the last day of GDPR?

    Nope it didn’t work for me

    Thread Starter tcress101

    (@tcress101)

    mikkelhusum thanks for that code, it works for me in the functions file. I think I’ve tried every single cookies plugin and none of them have exactly what I need. This is the closest atm so I’m grateful for your help!

    Thanks for the fix!

    Thread Starter tcress101

    (@tcress101)

    I just noticed some wonkiness when testing back and forth on Google Chrome and IE browsers, sometimes the code wasn’t inserted. I turned off WP Super Cache and cleared all cache files, this did the trick. I guess I’ll keep that off until things are running more smoothly.

    • This reply was modified 6 years, 6 months ago by tcress101.

    if(isset($_COOKIE['moove_gdpr_popup']) && $_COOKIE['moove_gdpr_popup']=='{\"strict\":\"1\",\"thirdparty\":\"1\",\"advanced\":\"1\"}') {

    This way all type of cookies must be accepted, is there a way to separate the functions (strict – thirdparty and advanced)?

    @tcress101

    Yes, I have experienced som issues with cache plugins too. But for me it works, when I have Cleared all caches.

    @oramweb

    Yes, there is a way to seperate the thirdparty and advanced. The cookie simply stores “1” or “0” depending on accept or decline. So you could just use the following code, if you want something else to happen depending on which settings the user accepts:

    if(isset($_COOKIE['moove_gdpr_popup']) && $_COOKIE['moove_gdpr_popup']=='{\"strict\":\"1\",\"thirdparty\":\"1\",\"advanced\":\"1\"}') {
    
    function all_scripts() { ?>
    <script>Insert your script here
    </script>
    
    <?php
    }
    add_action( 'wp_head', 'all_scripts' );
    }
    
    else if(isset($_COOKIE['moove_gdpr_popup']) && $_COOKIE['moove_gdpr_popup']=='{\"strict\":\"1\",\"thirdparty\":\"1\",\"advanced\":\"0\"}') {
    
    function thirdparty_script() { ?>
    <script>Insert your script here for the thirdparty settings.
    </script>
    
    <?php
    }
    add_action( 'wp_head', 'thirdparty_script' );
    }
    
    else if(isset($_COOKIE['moove_gdpr_popup']) && $_COOKIE['moove_gdpr_popup']=='{\"strict\":\"1\",\"thirdparty\":\"0\",\"advanced\":\"1\"}') {
    
    function advanced_script() { ?>
    <script>Insert your script here for the advanced settings.
    </script>
    
    <?php
    }
    add_action( 'wp_head', 'advanced_script' );
    }
    
    else {
        
    }

    Thanks, this is very helpful! @mikkelhusum

    the only issue I can see, if the user presses accept on the the main cookie banner to accept all cookies (the front accept button – without opening the popup) it should add all scripts.

    At the moment it does not add 3rd party or advanced – those you still have to enable in the popup.

    Is there a way that the cookie banner accept button can add all scripts. ‘Accept All’ etc.

    @rocked18

    The following code should set the script, if you accept all/or using the frontend accept button:

    if(isset($_COOKIE['moove_gdpr_popup']) && $_COOKIE['moove_gdpr_popup']=='{\"strict\":\"1\",\"thirdparty\":\"1\",\"advanced\":\"1\"}') {
    
    function all_script() { ?>
    <script>Insert your script here
    </script>
    
    <?php
    }
    add_action( 'wp_head', 'all_script' );
    }
    
    else {
        
    }
    • This reply was modified 6 years, 6 months ago by mikkelhusum.

    Ahh got it thanks! thats working well.

    This is great! Thank you again

    +1 –
    I think the moove guys should have built it like google tag manager, you add 2/3 shortcodes or code snippets to your theme file that prints the scripts inputted into the boxes into your theme.

    (which is essentially what we are now doing with the functions above)

    Is it fixed with the 1.1.0?

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Code Not Inserting Into Head Section Once Visitor Accepts Cookies’ is closed to new replies.