• Resolved Michael Collins

    (@mjcthreedee)


    Hi. My site is https://mjc3d.com. I’m a 3D artist. Most of my images are NSFW but a few are okay. I’m using the Nikkon theme.

    I’m also using AgeGate. In JavaScript mode. With Selected Content enabled.

    Nikkon is a photo-centric theme, and my home page is comprised of a masonry layout of thumbnails from the Featured Images of my works.

    Is there any way to make AgeGate work on the front page as well?

    I tried using the default Nikkon setup (with no separate Wordpess “Page” for Homepage or Posts) and that works fine if I want AgeGate to be on for everything.

    Then when I selected AgeGate to only be on for selected pages, the front page was visible again (along with the NSFW thumbnails).

    So then I tried creating a new WordPress “Page” called “Home” and manually turning on AgeGate for that “Page”.

    AgeGate still doesn’t trigger because it’s now the “Home Page” for my site.

    So I was wondering… is there a way to have AgeGate work for the “Home Page” for a site, in JavaScript mode, when Selected Content is enabled?

    Thanks so much for such a cool and invaluable plugin!

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

    (@philsbury)

    Hi @mjcthreedee,

    You absolutely can do that, just need a tiny bit of code.

    There’s two choices, a PHP version and a Javascript version. Both work with the Javascript version of Age Gate.

    PHP version (add to your functions.php or a tiny custom plugin):

    
    add_filter('age_gate_restricted', function ($restrict, $meta) {
        // $meta->type will be home, category, single etc
        if ('home' === $meta->type) {
            return true;
        }
        return $restrict;
    }, 10, 2);
    

    That’s it for the PHP version.

    For the JS version, first you need to enable JS hooks in the admin->advanced settings. But then, in a js file, the function is pretty much identical:

    
    ageGateHooks.addFilter('age_gate_restricted', 'age-gate', function(restrict, meta){
      if ('home' === meta.type) {
        return true;
      }
    
      return restrict;
    });
    

    You can use which ever is easier for you. The PHP version can have a bit of a delay as it has to do an ajax call, but depending on how much is loaded might do you.

    Cheers
    Phil

    Thread Starter Michael Collins

    (@mjcthreedee)

    This assumes I still have a custom “Page” called “Home” then configured? Just curious.

    Thread Starter Michael Collins

    (@mjcthreedee)

    Thank you! That did the trick.

    I duplicated the Hello Dolly plugin and edited the metadata and removed all the functions and replaced it with your add_filter.

    Then activated the plugin, and cleared all my caches.

    That did the trick!

    Thank you again!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Age Gate + JavaScript + Selected Content + HomePage’ is closed to new replies.