WordPress.org

Ready to get started?Download WordPress

Forums

Age Verify
[resolved] Could you add a code to block a category (4 posts)

  1. jadge
    Member
    Posted 1 year ago #

    Hi Chase,

    I love your plugin and using it on one of my website. Blocking a page/post is great but could you please make it block a category. As I have a category on my blog that is adult only and I want to block the category.

    Cheers mate.

    http://wordpress.org/extend/plugins/age-verify/

  2. Chase Wiseman
    Member
    Plugin Author

    Posted 1 year ago #

    The plugin has numerous hooks and filters so that you can extend its functionality fairly easily. It sounds like you'd need a custom function to tell the plugin to do some extra checking, something like this:

    function custom_restrict_category( $needs_verification ) {
    
        if ( is_category( $category )
            return true;
        else
            return false;
    }
    add_filter( 'av_needs_verification', 'custom_restrict_category' );

    You'd just need to change $category to the category ID/title that you want to restrict. More on what type of parameters is_category accepts here: http://codex.wordpress.org/Function_Reference/is_category

  3. previousnet
    Member
    Posted 10 months ago #

    Hello,

    Could you clarify a bit, I am just a beginner when it comes to this.

    Which plugin file does the above code snippet need to be added to?

    And you say change the $category to category ID/title.... does this mean the ID? or the Title?

    For example I have a category "nightlife" that I want to have the prompt installed for, and it is category #4, how would I integrate that in the code? and which file does it go in?

    Thanks

  4. l7world.com
    Member
    Posted 9 months ago #

    This works well but it's missing closing parenthesis.
    It should be:

    if ( is_category( $category ))

    also use "in_category" to restrict all category posts not archive page

    previousnet you can put code in functions.php, probably better to use your theme's instead the one for the plugin so it doesn't get overridden.

    Use

    if ( in_category( '4' ))

    or

    if ( in_category( 'nightlife' ))

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic