Display content only for logged users
How can I show content only for logged user or admin in my template?
Depending on what you want to test, just add one of these snippets to your template:
Check if user is connected as admin
1 2 3 4 5 | <?php if ( current_user_can( 'administrator' )) { // } ?> |
Check if user is connected as admin, editor or author
1 2 3 4 5 6 7 | <?php $user = wp_get_current_user(); $allowed_roles = array ( 'administrator' , 'editor' , 'author' ); if ( array_intersect ( $allowed_roles , $user ->roles ) ) { // } ?> |
Check if user is connected
1 2 3 4 5 | <?php if ( is_user_logged_in() ) { // } ?> |