I need to make some text visible in a text widget ONLY to logged in users. I'm using this conditional code directly in a sidebar text widget, but it does not work. It does not hide the text for anonymous users.Can you help please?
`<?php if (is_user_logged_in() ) { //only logged in user can see this ?>
<div><p>Text only for logged in users</p></div>
<?php } ?> `
Text widget visible only for logged in users
4 posts from 2 voices-
Posted 2 months ago #
-
Hi HouseofStrauss,
In order to use php in widgets, you need to use a plugin like: http://wordpress.org/extend/plugins/php-code-widget/
There is an example of is_user_logged_in on the codex which should help:
<?php if ( is_user_logged_in() ) { echo 'Welcome, registered user!'; } else { echo 'Welcome, visitor!'; } ?>Regards,
Devin
Posted 2 months ago # -
Ok, thanks Devin, just wondered if the theme had removed the code filters by default. Obviously not. Thanks...
Posted 2 months ago # -
Hey HouseofStrauss,
No I don't believe so but I wasn't sure if you might have been trying it in a regular text widget or may not have had the example as a reference for correct syntax :)
Regards,
Devin
Posted 2 months ago #
Reply
You must log in to post.














