Are you want to add new custom user role in your WordPress site? If your answer is yes, then this tutorial is for you. In this tutorial, I am going to share how to add custom WordPress user role with the help of add_role()
function.
Add the below code inside your functions.php or you can also add inside your custom plugin file. In the below code we are going to add a new custom WordPress user role as “Guest Blogger” with the only required access of WordPress admin area.
1 2 3 4 5 6 7 8 9 10 11 | add_role('guestblogger', 'Guest Blogger', array( 'read' => true, // True allows that capability, False specifically removes it. 'edit_posts' => true, 'delete_posts' => true, 'edit_published_posts' => true, 'publish_posts' => true, 'edit_files' => true, 'import' => true, 'upload_files' => true, )); |
Use the below code to remove any custom or standard user role from your WordPress websites.
1 2 | // To remove one outright or remove one of the defaults: remove_role('guestblogger'); |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.