Skip to content

Instantly share code, notes, and snippets.

@pareshsojitra
Forked from devinsays/redirect-admin.php
Created February 7, 2021 15:14
Show Gist options
  • Save pareshsojitra/fce23b3b2dfd662df9d913febbfaf955 to your computer and use it in GitHub Desktop.
Save pareshsojitra/fce23b3b2dfd662df9d913febbfaf955 to your computer and use it in GitHub Desktop.
Redirects subscribers back to the home page if they attempt to access the dashboard.
<?php
/**
* Redirects subscribers back to the home page if they attempt to access the dashboard.
*/
function prefix_redirect_admin() {
if ( ! current_user_can( 'edit_posts' ) && ! defined( 'DOING_AJAX' ) ) {
wp_safe_redirect( home_url() );
exit;
}
}
add_action( 'admin_init', 'prefix_redirect_admin' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment