• Hello,
    If my English is messed up, I am sorry
    I’m a Japanese person who can’t talk

    I have read about here
    I use Javascript because of the cache.

    
    add_filter('age_gate_unrestricted_unrestricted', function ($restricted, $meta) {
      if (preg_match('/campaign_r20/',$_SERVER["REQUEST_URI"])) { 
            return true;
        }
        return $restricted;
    }, 10, 2);
    

    How do I use this code in Javascript?
    When it was not Javascript, it worked normally

    How can I add age gate to homepage on that case ?

    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Phil

    (@philsbury)

    Hi @lilybrownie,

    If you just want to restrict some pages you could use selected content mode and just pick the ones you want. But if you need it programatically, here’s how you’d do it in JavaScript.

    First, you need to enable the JavaScript hooks

    Then in your javascript file, you can do:

    
    function conditionallyAllow(restrict, meta){
        return window.location.pathname.match(/campaign_r20/g);
    }
    if(typeof ageGateHooks !== 'undefined'){  
        ageGateHooks.addFilter('age_gate_restricted', 'age-gate', conditionallyAllow);
    }
    

    This will just restrict a url with campaign_r20 in it like your PHP example.

    Hope that helps

    Thanks
    Phil

    Thread Starter lilybrownie

    (@lilybrownie)

    Hi @philsbury

    It seems that you can do what you wanted to do.

    But let me ask you another question
    In javascript mode, you can see the code of the page to be displayed after performing age authentication.
    Is it possible to hide this?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Age gate only on home page and specific pages with JavaScript’ is closed to new replies.