Monday, November 28, 2022
WordpressWordpress HooksWordpress Tricks

How to create new user role in WordPress and add capability to that role?

Wordpress trick to check term id has parent term or child term

Hello to all, welcome to In this post, I will tell you, How to create new user role in WordPress and add capability to that role?

WordPress is the best part for me in developer websites.

We will create new user role like “administrator” with wordpress custom functionality. We will create “employee” user role and we will also add capability like edit post, add post etc.

Here is the code and you need to add this code in your theme’s functions.php file:

function add_theme_caps() {
    __( 'Therichpost Employee' ),
      'read'           => true,  // true allows this capability
      'edit_posts'     => false,
      'delete_posts'   => false, // Use false to explicitly deny
      'manage_options' => false
    ) );

  // gets the author role
  $role = get_role( 'employee' );

       // add capability to the author role
  $role->add_cap( 'view_dashboard' );

add_action( 'admin_init', 'add_theme_caps' );


This is it, if you have any query related to this post or you want any kind information related wordpress then please let me know.

Jassa jatt

Thank you

the authortherichpost
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 8, Angular 9, Angular 10, Angular 11, Angular12, Angular 13, Angular 14, Angular 15, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.