How to put this code into an echo?
<?php
if ( is_user_logged_in() ) {
echo 'Welcome, registered user!';
} else {
echo '**Here**';
}
?>
I want to put the code right into the echo, i am newbie in php, i tried changing the " into ' or putting the php strings into the code in another way, i tried everything i was able to search on google and i knew. But nothing worked, i was only able to see a blank page. Could anyone help me understand how to change html and make it fit into the echo? Thank you very much.
<div class="top-bar-login">
<div id="adv-bar-top">Cosa aspetti ad iscriverti?</div>
<div class="clear"></div>
<div id="other-bar-top">
<a href="/forums">Forum</a>
<a href="/bacheca">Community</a>
<a href="/help">Help</a>
<a class="lbp-inline-link-2" href="#">Login</a>
<a href="/registrati" class="button-signup-top-bar">Iscriviti</a>
</div>
</div>
<div style="display: none;">
<div id="lbp-inline-href-2" style="padding:10px; background: #fff;">
<div id="login-form">
<h3>Login</h3>
<fieldset>
<form action="<?php bloginfo('wpurl') ?>/wp-login.php" method="post">
<input type="text" name="log" id="log" required value="Email" onBlur="if(this.value=='')this.value='Email'" onFocus="if(this.value=='Email')this.value='' ">
<input type="password" name="pwd" id="pwd" required value="Password" onBlur="if(this.value=='')this.value='Password'" onFocus="if(this.value=='Password')this.value='' ">
<input type="submit" name="submit" value="Login">
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>"/>
<footer class="clearfix">
<p><span class="info">?</span><a href="/wp-login.php?action=lostpassword">Password Dimenticata?</a>
</p>
</footer>
</form>
</fieldset>
</div>
<!-- end login-form -->
</div></div>
PS: I am working with wordpress.
<?php
if ( is_user_logged_in() ) {
echo 'Welcome, registered user!';
} else {
?>
insert html here
<?php
}
?>
PHP allows to write like this this:
<?php if (condition1){ ?>
HTML or whatever if condition1 is true
<?php }elseif (condition2){ ?>
HTML or whatever if above is false and condition2 is true
<?php }else{ ?>
HTML or whatever if all above are false
<?php } ?>
<?php
if ( is_user_logged_in() ) {
echo 'Welcome, registered user!';
} else {
?>Insert HTML here!<?
}
?>
It only adds the HTML if is_user_logged_in() == false
from the else
.