• I want to hide some content on a page from logged in users so that only logged out users can see it.

    Is there a plugin/hack to do this?

    I would be very grateful!

    Thanks
    Keir

Viewing 5 replies - 1 through 5 (of 5 total)
  • I can think of several things you could do.

    1) WordPress inserts a body class that reflects a user’s ‘logged in” status (assuming your theme uses the body_class() function). If you can put your content in a span of div with the appropriate class you can hide it with CSS.

    2) You could also write the condition into your template(s).

    3) Or make a shortcode.

    Really, the best option for you depends upon exactly what you want to do. Is the “logged out” content the same for all posts? Do you need to insert the “logged out” content into each post individually? Would you care if a logged in user saw the “logged out” content by viewing the page source?

    Thread Starter iKeirNez

    (@ikeirnez)

    I think short code would be the best. I am manually creating register, login & forgot password pages. It all works and I can sign in perfectly. I created a Text/HTML widget with the links and used the Widget Logic plugin to hide but it can still be accessed in the URL. It is a Website Design website so I would like it hidden to make it look better.

    I would rather not use the <!– and –> to hide it if an admin is logged in but this would be a last resort. It is only 2 pages that need stuff hidden and I would like to have custom text on the page too.

    I hope you can help.

    Thanks
    Keir

    I would rather not use the <!– and –> to hide it if an admin is logged in but this would be a last resort.

    There is no reason you should have to do that. I hadn’t even thought about using html comments to hide things. I wouldn’t do that either, not in this context.

    The shortcode type you need, as I understand it, is the enclosing shortcode. The codex has just about everything you need to make this work.

    Thread Starter iKeirNez

    (@ikeirnez)

    I don;t know how to do that. Would it not be easier getting the PHP Exec plugin and using <?PHP ……. ?> to hide it.

    Here is the code:

    <?php if (is_user_logged_in() ) { //only logged in user can see this ?>
    <div><p>I love green tea!</p></div>
    <?php } ?>

    I worked out how to do it for logged out users

    <?php if (!is_user_logged_in() ) { //only logged in user can see this ?>
    <div><p>I love green tea!</p></div>
    <?php } ?>

    iKeirNez

    Thanks for that code. That is exactly what I was looking for on my site. Worked great!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hide Some Page Content to Logged In Users’ is closed to new replies.