A
A
Andrew2020-07-22 03:24:16
WordPress
Andrew, 2020-07-22 03:24:16

Remove button in wordpress based on role?

Good day, tell me how to remove the button using the user role.
Let's say I need to remove the personal account button for the subscriber role.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Osadchy, 2020-07-22
@DELUX

You need to look at this article
Hide the button from the "Subscriber" role

<?php
if ( !current_user_can( 'subscriber' ) ) { ?> 
  <button>Кнопка для всех (кроме подписчиков)</button>
<?php } ?>

Let's display the button for administrators only:
<?php
// Видно будет только администраторам
if ( current_user_can( 'administrator' ) ) { ?> 
  <button>Кнопка для администратора</button>
<?php } ?>

List of default roles:
current_user_can('administrator') // false
current_user_can('editor') // true
current_user_can('contributor') // false
current_user_can('subscriber') // false

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question