Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

1 Answer

M Glasser
M Glasser
10,868 Points

Just starting to get the hang of php and WordPress myself and this might be a possible wrong solution... but my first instinct would be to alter the php file where the element is to be displayed. Check for the log in condition then if it's true do nothing and if it's false echo the element you want to show. The element will then only show if user is logged in.

https://developer.wordpress.org/reference/functions/is_user_logged_in

Austin Whipple
Austin Whipple
29,725 Points

This is probably your safest bet.

WordPress does, if you use <body <?php body_class(); ?>>, add a logged-in class to the body element. However, the element is still output to the HTML, so a user could conceivably see what you're trying to hide if CSS doesn't load or through Developer Tools. Especially bad news if there's any sort of security concern.

I'd go with the is_user_logged_in option to be safe.