• Hi, I’m wondering how I can hide the consent bar on specific posts and pages?

    Specifically because I’m making a landing page with the Divi Theme, and I’d rather not have the consent bar on it.

    Thanks,
    Alex

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author dFactory

    (@dfactory)

    Hi,

    It’s pretty easy to do with some basic PHP.
    Just use WP template tags https://codex.www.ads-software.com/Template_Tags to define where you want the banner to be hidden and apply one of the two action hooks:

    // Disable Cookie Notice
    add_filter( ‘cn_cookie_notice_output’, ‘__return_false’ );

    // Disable Cookie Compliance
    add_filter( ‘cn_cookie_compliance_output’, ‘__return_false’ );

    Hope this helps,

    Sorry to jump in but I did just that to achieve something similar (but then site wide).

    It then gives an error in the console log:

    Uncaught TypeError: Cannot read properties of null (reading 'classList')
        at Object.init (front.min.js?ver=2.2.3:1:6939)
        at front.min.js?ver=2.2.3:1:8399

    It looks to me your js assumes the class is always there. I think you might need to adapt your JS so it can handle it when the class is non-existent.

    Just found out, this can be fixed by adding an empty div with id=”cookie-notice”.

    function tk_cookie_output( $output ) {
        if ( $your_condition ) {
            $output = '<div id="cookie-notice"></div>';
        } else {
            $output = preg_replace('/<!--(.*)-->/Uis', '', $output);
        }
    
        return $output;
    }
    add_filter( 'cn_cookie_notice_output', 'tk_cookie_output' );

    If your condition is met, it’s hidden, if not, it strips their branding from the source code.

    Thread Starter Alex Ford

    (@alexford)

    Thank you @dfactory!

    Someone helped me create the following MU plugin (In case anyone else is interested!):

    File name: disable-cookie-notice.php

    <?php
    /**
     * Plugin Name: Disable Cookie Notice
     * Description: Hides the cookie notice on specific page IDs for the Cookie Notice & Compliance for GDPR/CCPA plugin by Hu-manity.co
     */
    
    function tk_cookie_output( $output ) {
    if (is_page(array(123456,789012,345678) ) ) {
    $output = '<div id="cookie-notice"></div>';
    } else {
    $output = preg_replace('/<!--(.*)-->/Uis', '', $output);
    }
    
    return $output;
    }
    add_filter( 'cn_cookie_notice_output', 'tk_cookie_output' );
    
    ?>

    Note that you can insert multiple page IDs separated by a comma in this section:

    if (is_page(array(123456,789012,345678) ) ) {

    Or an individual page ID as follows:

    if (is_page(array(123456) ) ) {

    • This reply was modified 2 years, 7 months ago by Alex Ford.
    • This reply was modified 2 years, 7 months ago by Alex Ford.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Hide on specific posts and pages’ is closed to new replies.