Widget Logic
[resolved] user logged in syntax help (3 posts)

  1. mridl200
    Posted 4 years ago #

    Hey guys,
    I am trying to script a small amount of php to change a link based on if the user is logged in or not.

    What I have is :
    if ( is_user_logged_in() ) {
    echo 'Welcome, registered user!';
    } else {
    echo 'Welcome, visitor!';

    However I dont really understand how widget logic works. When I place this code in my footer widget any text from that widget is removed and nothing is shown. Ive tried changing the settings to load after all php has been loaded since is_user_logged_in() is part of a different php script but still did not work.
    Any help is appreciated, thanks!


  2. alanft
    Plugin Author

    Posted 4 years ago #

    If you put


    as the Widget Logic for a widget, that widget will only appear if the user is logged in. What is displayed in the widget is not controlled by widget logic. So you could e.g. have 2 'text' widgets, one with is_user_logged_in() and one with !is_user_logged_in(), where ! means 'NOT the case that'.

    Hope that helps

  3. mridl200
    Posted 4 years ago #

    That makes perfect sense. Thank you for clearing that up for me.
    I ended up making the two different text widgets like you suggested with
    is_user_logged_in() displaying a different link than when a user is logged out as I originally intended to make.

    Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic