Change Default WordPress User Role
Custom Code Solution
This code changes the default user role for new registrations from "subscriber" to any role you specify. Add this code to your theme's functions.php
file or in a site-specific plugin:
add_filter('default_role', function($default_role) {
return 'subscriber'; // Change 'subscriber' to your desired default role
});
Available WordPress default roles you can use:
- administrator
- editor
- author
- contributor
- subscriber
Enhanced Solution with Role Verification
This extended version includes a safety check to ensure the role exists before setting it:
add_filter('default_role', function($default_role) {
$new_default_role = 'subscriber'; // Change this to your desired role
// Verify role exists before setting it
if (get_role($new_default_role)) {
return $new_default_role;
}
return $default_role; // Fallback to WP default if specified role doesn't exist
});
Where to Place the Code
- In your theme's
functions.php
file
- In a site-specific plugin
- Via a code snippets plugin
Plugin Solutions
If you prefer using a plugin, here are reliable options:
-
Members - Complete user role management
-
User Role Editor - Advanced role customization
-
Code Snippets - To implement the code solution without editing theme files
Additional Notes
- The code takes effect immediately after implementation
- It only affects new user registrations
- Existing users' roles remain unchanged
- You can verify the current default role in WordPress admin under Settings → General → New User Default Role