Skip to content

Instantly share code, notes, and snippets.

@mmarj
Forked from devinsays/redirect-admin.php
Created May 14, 2022 15:54
Show Gist options
  • Save mmarj/2d9a87d44c5acb6722e4a5fb7d599a9c to your computer and use it in GitHub Desktop.
Save mmarj/2d9a87d44c5acb6722e4a5fb7d599a9c 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