WordPress: Redirect users when trying to access a specific page

/* add to functions.php */ add_action( 'template_redirect', function() { if ( is_user_logged_in() || ! is_page() ) return; $restricted = array(6476); if ( in_array( get_queried_object_id(), $restricted ) ) { wp_redirect( site_url( '/login-registo' ) ); exit(); } });

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.