I like to secure a certain page for admins. How do I check if a user is logged (and is admin)? Of their not logged in, I want to show the login module.
2 Answers
if(!current_user_can('administrator')) {
wp_redirect( wp_login_url() );
}
This will redirect non-admins to login URL. Of course, logged in non-admins will be a bit confused. You’ll want to run this before get_header()