Show/Hide Content Based On User Role in WordPress


/ Published in: PHP
Save to your folder(s)

Customize as needed using user roles.


Copy this code and paste it in your HTML
  1. <?php if (is_user_logged_in() ) { //only logged in user can see this ?>
  2. <div><p>You are logged in!</p></div>
  3. <?php } ?>
  4.  
  5. <?php if ( current_user_can( 'delete_others_posts' ) ) { //only admins and editors can see this ?>
  6. <p>You are an admin</p>
  7. <?php } else { ?>
  8. <p>You are not an admin</p>
  9. <?php } ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.