skip to Main Content

I’m trying to make it so that I can go to the pages of only certain authors, and a redirect will work for the rest. I’m trying to do this through is_author, but it does not accept meta arguments, and does not understand != Perhaps someone knows how to solve this problem. Thank you!

i tried this in function.php :

function redirect_author_page() {
global $wp_query;

if (is_author($author != array('name1', 'name2'))) {
    wp_safe_redirect(get_option('home'), 301); 
    exit; 
}

}

add_action(‘template_redirect’, ‘redirect_author_page’);

2

Answers


  1. According to an example in the docs of the function is_author

    if (is_author(array('name1', 'name2'))) {
      // do this
    } else {
      // do that
    }
    
    Login or Signup to reply.
  2. != means not equal, but doesn’t work in this instance. If you wanted to use it in the case of is_author() you’d add the ‘not’ at the beginning. You also need a comma separating the parameters.

    if (!is_author($author, array('name1', 'name2'))) {
        wp_safe_redirect(get_option('home'), 301); 
        exit; 
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search