0

In my css i have a hidden div id:

#example {display:none;}

How can I set this to display:block for logged in users only?

I am assuming using Jquery would be the best option here for best performance? Or is it better to use a function in functions.php ?

1
  • Where and how are you defining your CSS? Commented Nov 6, 2013 at 16:52

1 Answer 1

6

You need to use the body_class(): http://codex.wordpress.org/Function_Reference/body_class

If you use the function body_class() you can set on your css like this:

.example {
    display: none;
}
.logged-in .example {
    display: block
}
4
  • awesome - had no idea about this class :) thank you guys xx
    – JoaMika
    Commented Nov 6, 2013 at 17:04
  • Joanna Mikalai you're welcome. @ChipBennett =D Commented Nov 7, 2013 at 4:47
  • I have a problem using this technique: I have setup a menu item (custom link) with class logout and the following CSS #toolbar .logout a{ display:none; } #toolbar .logged-in .logout a{ display:inline; } But when logged-in, the link is invisible. body_class() is being used because when user is logged-in in can see in the source of the page the class .logged-in is being injected in the code. Here's the link: me-about.me/test
    – Riccardo
    Commented Jun 10, 2016 at 13:54
  • Hello @Riccardo you could use .toolbar .logout { display: none } .logged-in .toolbar .logout { display: inline } Commented Jun 22, 2016 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.