Answer the question
In order to leave comments, you need to log in
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
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 );
function redirectUnlogged() {
$id = 1;
if (is_page($id) && !is_user_logged_in()) {
wp_redirect('yourl_link.ru', 302);
exit;
}
}
add_action( 'init', 'redirectUnlogged' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question