• I have a completely custom “Home Page” with some links to various other parts of my site. I also want to add a “Register” and “Login” link using my own code, so my question is, does WordPress have conditional statements where I can set it to only show certain code if, for example, someone is logged in or not? Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter zoldos

    (@zoldos9)

    Okay it does after a Google search. I want to use the one for if a user is logged in or not. But I’m working with HTML and CSS. So how can I use this conditional which appears to be PHP?

    You can use PHP inside any WordPress template file – eg:

    <?php is_user_logged_in() :?>
    [do HTML stuff]
    <?php endif;?>
    Thread Starter zoldos

    (@zoldos9)

    It doesn’t seem to work. I tried this:

    <?php if is_user_logged_in() :?><?php else:?><button class="button222 glass blue-b" type="button" onclick="location.href='/wp-login.php?action=register'">Create Account</button><button class="button222 glass blue-b" type="button" onclick="location.href='/wp-login.php'">Login</button><br><?php endif;?>

    I basically want to display these two links to anyone NOT logged on…

    • This reply was modified 8 years, 1 month ago by zoldos.

    I don’t see any reason why this won’t work for you.

    <?php if ( !is_user_logged_in() ) { ?>
        <button class="button222 glass blue-b" type="button" onclick="location.href='/wp-login.php?action=register'">Create Account</button>
        <button class="button222 glass blue-b" type="button" onclick="location.href='/wp-login.php'">Login</button>
    <?php } ?>

    Hope this helps.

    Thread Starter zoldos

    (@zoldos9)

    Thanks, but it doesn’t work….do I need an “Insert PHP into Page” plugin?

    These codes should be added to your template file that has been assigned to whichever page is your Home page.

    Thread Starter zoldos

    (@zoldos9)

    I am using them in a Page itself. I found a plugin that might work tho! ??

    Thread Starter zoldos

    (@zoldos9)

    Still not working. ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘does WordPress support conditional statements?’ is closed to new replies.