Steps
-
Add the PHP code to your child theme’s
functions.phpfile or the Code Snippets plugin. -
Save and activate the snippet.
-
Log in using a Subscriber account and try to open the WordPress dashboard.
Hook Used
– admin_init — Runs during WordPress admin initialization and redirects matching users.
Type: WordPress Access Customization
Output: Users with the Subscriber role are redirected to the website homepage when accessing the admin area.
Note: This is a dashboard redirect, not a complete security system. It targets users with the subscriber capability check; if you want to target the exact Subscriber role, check the user’s role explicitly. Admins and other roles are not affected by this snippet.
function custom_redirect_subscriber_dashboard() {
if (
is_admin()
&& ! wp_doing_ajax()
&& current_user_can( 'subscriber' )
) {
wp_safe_redirect( home_url( '/' ) );
exit;
}
}
add_action( 'admin_init', 'custom_redirect_subscriber_dashboard' );
Tested on
Reported by the author on October 17, 2026. WPFolks has not verified this.
Not tested against WordPress 7.1.4. It may still work.
