B
B
Bearax2017-04-03 16:31:44
CMS
Bearax, 2017-04-03 16:31:44

How to disable access to a specific page in Wordpress?

I want to make it through functions.php so that only registered users have access to a certain page, so that when they go to this page, unregistered users are redirected to another specific page.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2017-04-03
@Bearax

is_page
is_user_logged_in
wp_redirect

function prefix_redirect_function() {
  if ( is_page(42) && !is_user_logged_in() ) { // 42 это ID 
    // редирект на главную:
    wp_redirect( home_url() );
    // или так на url:
    // wp_redirect( 'http://www.example.com', 301 ); 
    exit;
  }
}
add_action( 'template_redirect', 'prefix_redirect_function', 9 );

F
fuck__all__humans, 2017-04-03
@fuck__all__humans

function redirectUnlogged() {
  $id = 1;
  if (is_page($id) && !is_user_logged_in()) { 
     wp_redirect('yourl_link.ru', 302);
     exit;
  }
}
add_action( 'init', 'redirectUnlogged' );

Google functions is_page(), is_user_logged_in(), wp_redirect() and using hooks in worpdress

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question