Skip to content

Instantly share code, notes, and snippets.

@trueqap
Created January 25, 2018 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trueqap/089c3ec3ca34659da3bc37085e51cd2e to your computer and use it in GitHub Desktop.
Save trueqap/089c3ec3ca34659da3bc37085e51cd2e 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