Restrict Non-WordPress Page Access to Logged in User

This is useful for non WordPress pages on a WordPress installation.

Add this to the top of the page:


if(!current_user_can('editor')) {
    wp_redirect( wp_login_url() );

To restrict access to admin only change “editor” to “administrator”.

wp-load.php loads the WordPress functions so yo can use the current_user_can() function