• Resolved Notfunny01

    (@notfunny01)


    Hi,

    I have tried using the ‘ is_allowed_cookie( $cookie ) ‘ helper function to wrap code to block a cookie, I have experimented with a google gpt publisher tag snippet to see if I can get the helper function to work. The cookie is registered as an optional cookie under Advertising. What am I missing here?

    Should the function not somehow be added to the functions.php file first and/or in a child theme?

    What I have done looks like this:

    if ( is_allowed_cookie( ‘CONSENT’ ) {
    // Run my code and set the cookie.
    <script async src=”https://securepubads.g.doubleclick.net/tag/js/gpt.js”></script&gt;
    }
    <script>
    window.googletag = window.googletag || {cmd: []};
    googletag.cmd.push(function() {
    googletag.defineSlot(‘/21714798789/GE-Native-Bloc1’, [[250, 360], [300, 600], ‘fluid’], ‘div-gpt-ad-**********-0’).addService(googletag.pubads());
    googletag.pubads().enableSingleRequest();
    googletag.pubads().collapseEmptyDivs();
    googletag.enableServices();
    });
    </script> (I blanked out the Ad number)

    But i have tried it several different ways, with several different cookies that are set by that same script.

    The Ad code with the wrap function is injected into the header of each chosen post/page via Ad-Inserter, a plugin for injecting ad code, or any code, into chosen posts/pages on a site. But that shouldn’t make any difference surely?

    Clearly i am missing something, no?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Fernando Claussen

    (@fclaussen)

    Hi,

    I’m not sure about your implementation specifically but if you wrap code that creates cookies in that check they do work.

    I can’t really identify where is the problem as the problem isn’t related to this plugin.

    Thread Starter Notfunny01

    (@notfunny01)

    Hi,

    I meant can anyone explain how to get the wrap code to work?

    I thought the code is part of the plugin’s functionality to Enable/Disable Cookies.

    Unfortunately. I can keep trying, but so far I cannot get the plugin to block cookies!

    Thanks.

    • This reply was modified 4 years, 6 months ago by Notfunny01.
    Thread Starter Notfunny01

    (@notfunny01)

    And so, for anyone interested, I found the best way to get the is_allowed_cookie( $cookie ) helper function to work for a third-party script was to embed it with <? , { ?>, and closing <?php } ?> tags/brackets.

    This I put in the Child Theme’s header.php for enabling/disabling Google/Doubleclick Ads/ cookies:

    <? if ( is_allowed_cookie( ‘DSID’ ) ) { ?>
    <script async src=”https://securepubads.g.**********.***/tag/js/gpt.js”></script&gt;
    <script>
    window.googletag = window.googletag || {cmd: []};
    googletag.cmd.push(function() {
    googletag.defineSlot(‘/2**********/**-300-250-Foot’, [[300, 250], ‘fluid’], ‘div-gpt-ad-1575242906284-0’).addService(googletag.pubads());
    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
    });
    </script>
    <?php } ?>

    Except this did not work where you are trying to insert the function within an existing script, in which case it could cause syntax errors. So for example I did this to Enable/Disable Social Media Cookies/Sharing Buttons in Jetpack:

    if (is_allowed_cookie( ‘fr’ ) ) { $sharing_markup = apply_filters( ‘jetpack_sharing_display_markup’, $sharing_content, $enabled );
    }

    As said in the plugin guide, the cookies must be named and listed in the plugin’s user interface for any of this work, as with Consents.

    Just in case anyone, like me, still needed to know!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘php helper function not working?’ is closed to new replies.