How to Display Different Content for Logged-In Users in WordPress

September 9, 2025
How to Display Different Content for Logged-In Users in WordPress

Sometimes you may want to show certain content only to logged-in users—such as premium resources, downloads, or member-only messages—while showing alternative content to visitors. WordPress makes this possible with simple conditional checks in your theme, page templates, or shortcodes.

Method 1: Using is_user_logged_in() in Templates

The is_user_logged_in() function checks if a visitor is logged in. You can use it in your theme files (e.g., page.php, single.php, or custom templates).

<?php if ( is_user_logged_in() ) : ?>
    <p>Welcome back! Here is your exclusive content.</p>
<?php else : ?>
    <p>Please <a href="<?php echo wp_login_url(); ?>">log in</a> to view this content.</p>
<?php endif; ?>

This will display one message to logged-in users and another to visitors.

Method 2: Creating a Shortcode

You can also create a shortcode to conditionally display content in posts, pages, or widgets.


// Shortcode: [member_content]Protected content[/member_content]
function my_member_content_shortcode( $atts, $content = null ) {
    if ( is_user_logged_in() ) {
        return do_shortcode( $content );
    } else {
        return '<p>You must <a href="' . wp_login_url() . '">log in</a> to see this content.</p>';
    }
}
add_shortcode( 'member_content', 'my_member_content_shortcode' );

Usage example inside a post or page:

[member_content]
This text is visible only to logged-in users.
[/member_content]

Method 3: Show/Hide Widgets for Logged-In Users

If you want widgets to behave differently, you can wrap them in a conditional check or use plugins like Widget Logic or Content Visibility for Blocks. With is_user_logged_in(), you can control widget output like this:

<?php if ( is_user_logged_in() ) : ?>
    <div class="widget">Exclusive member widget content</div>
<?php endif; ?>

Method 4: Restrict Content by User Role

Sometimes you don’t just want to restrict content to logged-in users, but also by role (e.g., only administrators or subscribers). Use current_user_can():

<?php if ( current_user_can('administrator') ) : ?>
    <p>This content is visible only to administrators.</p>
<?php endif; ?>

Summary

  1. Use is_user_logged_in() in templates to display different content for members and visitors.
  2. Create a shortcode for flexible use inside posts and pages.
  3. Show or hide widgets based on login status with conditionals or plugins.
  4. For more control, use current_user_can() to restrict by user role.

By using these techniques, you can create member-only areas, premium downloads, or personalized messages for logged-in users, while still providing alternative content for visitors.

Avatar

Written by

satoshi

I’ve been building and customizing WordPress themes for over 10 years. In my free time, you’ll probably find me enjoying a good football match.