• Resolved Newki75

    (@newki75)


    Hi guys,

    I need to hide a post category for a specific role, is it possible?
    Nice day,
    Marine

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

    (@caseproof)

    Hi Marine,

    You can try to use this code snippet that uses “is_category” condition and adjust as you want:

    add_action( 'template_redirect', function() {
      // Redirect users from specific page 
      // when user doesn't have particular role 
      $user = wp_get_current_user();
      if ( is_category('your-category') && ( ! is_user_logged_in() || ( ! empty($user) && in_array( 'author', (array) $user->roles ) ) ) ) {
        $redirect = 'https://your-domain.com/wp-login.php'; // Change this to the correct URL
        wp_redirect( $redirect );
        exit;
      }
    } );

    To use it, you need to insert the code at the end of your theme’s functions.php file or install this plugin: https://www.ads-software.com/plugins/code-snippets/ and add it there.

    Hopefully, that helps.

    Thread Starter Newki75

    (@newki75)

    Tx ! Will try that

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide a post category for an Editor?’ is closed to new replies.