How to Display Text to Only Logged in WordPress Users

Create Shortcode for Logged in Users

function logged_in_only_shortcode($atts, $content = null) {
    if (is_user_logged_in() && !is_null($content) && !is_feed()) {
        return $content;
    }
}
add_shortcode('logged_in_only', 'logged_in_only_shortcode');

To use this shortcode in your post use the following code.


Create Shortcode for Logged Out Users

function logged_out_only_shortcode($atts, $content = null) {
    if (!is_user_logged_in() && !is_null($content) && !is_feed()) {
        return $content;
    }
}
add_shortcode('logged_out_only', 'logged_out_only_shortcode');

To use this shortcode in your post use the following code.

User is logged out.

Resource: Display Text To Only Logged In WordPress Users

Leave a Comment

Your email address will not be published. Required fields are marked *