• Hi there,

    Is there a way to age gate all posts of a certain type? I see how to shut off the age gate for certain post types, but not the reverse. I have a page that displays several cannabis strain posts. If a user accesses through the page, they have to go through the age gate, but if they search for a particular cannabis strain and are taken directly to the post, it bypasses the age gate. I want users to only have to go through the age-gate once, and not on each page though. Any ideas?

    Jordana

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Phil

    (@philsbury)

    Hi @cannamomma,

    This is possible with a bit of code and some backwards thinking!

    They way I think I’d do it is to restrict everything by default and bypass if it’s not the custom post type.

    So first, set the age gate restriction settings to be All content.

    Then in you functions.php/a custom plugin bypass the age check on anything that isn’t your post type. Let’s assume your post type is called book for the sake of this example:

    add_filter('age_gate_restricted', function ($restricted) {
        if (get_post_type() !== 'book') {
            return false;
        }
    
        return $restricted;
    }, 10, 1);

    Just change book to whatever you have as a CPT and you should be good to go

    Thanks
    Phil

Viewing 1 replies (of 1 total)
  • The topic ‘Age gating multiple sections of website’ is closed to new replies.