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
<?php if( current_user_can('administrator')) { // } ?>
Check if user is connected as admin, editor or author
<?php $user = wp_get_current_user(); $allowed_roles = array('administrator','editor','author'); if( array_intersect($allowed_roles, $user->roles ) ) { // } ?>
Check if user is connected
<?php if ( is_user_logged_in() ) { // } ?>