Make A WordPress Page Accessible To Admins Only, Redirect Other User Roles

admin_init runs on admin pages, not the front end. The equivalent front end action, init, is too early to check is_page. A safe action for redirection is template_redirect:

function xyz() {
    if( is_page( 172 )
        && ! current_user_can('update_core') ) {
            wp_redirect( home_url() );
            exit;
    }   
}
add_action( 'template_redirect', 'xyz' );

Leave a Comment