Skip to content

Instantly share code, notes, and snippets.

@hslaszlo
Forked from trueqap/hide_admin.php
Created January 28, 2018 07:24
Show Gist options
  • Save hslaszlo/8acb278d7f3602e3bd86d7d07700eeb1 to your computer and use it in GitHub Desktop.
Save hslaszlo/8acb278d7f3602e3bd86d7d07700eeb1 to your computer and use it in GitHub Desktop.
Hide admin for NON-ADMIN users WordPress - Redirect non-admin users to home page
<?php
add_action( 'admin_init', 'redirect_non_admin_users' );
function redirect_non_admin_users() {
if ( ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) {
wp_redirect( home_url() );
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment