Skip to main content
Login Join
Snippet · PHP

Add a Custom Roles with permissions

Shared by Mukesh Gujjar · July 6, 2026 · @init

19 views
2 upvotes
Back to Snippets

To add a new user role in WordPress, you use the add_role() function. You can place this snippet in your active theme’s functions.php file or within a custom plugin.

Here is the standard snippet to create a custom role (in this example, a “Manager”)

/**
* Add a custom user role.
*/
function wp_add_custom_user_role() {
// Check if the role already exists to avoid unnecessary database writes
if ( ! get_role( 'manager' ) ) {
add_role(
'manager', // Internal role name (lowercase, no spaces)
__( 'Manager' ), // Display name for the WordPress admin area
array(
'read' => true, // Allows the user to read content
'edit_posts' => true, // Allows the user to edit their own posts
'upload_files' => true, // Allows the user to upload media
'delete_posts' => false, // Denies the user the ability to delete posts
)
);
}
}
// Hook into 'init' to execute the function
add_action( 'init', 'wp_add_custom_user_role' );
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments