Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #21225

    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 } ?> `

    #111057

    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

    #111058

    Ok, thanks Devin, just wondered if the theme had removed the code filters by default. Obviously not. Thanks…

    #111059

    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

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Text widget visible only for logged in users’ is closed to new replies.