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.

[logged_in_only]User is logged in.[/logged_in_only]

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.

[logged_out_only]User is logged out.[/logged_out_only]

Resource: Display Text To Only Logged In WordPress Users

Leave a Reply

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