Skip to content

Instantly share code, notes, and snippets.

@devinsays
Last active May 14, 2022 15:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save devinsays/e7a4d3d889069e5c40f7 to your computer and use it in GitHub Desktop.
Save devinsays/e7a4d3d889069e5c40f7 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