Reputation: 743
I have 2 inputs, one for username, and one for ID.
Username value: <?php echo esc_attr( get_option('username') ); ?>
ID value: <?php echo esc_attr( get_option('id') ); ?>
and a division:
<div id="info"><?php echo esc_attr( get_option('username') ); ?></div>
I want a PHP function to echo <?php echo esc_attr( get_option('ID') ); ?>
in div#info ONLY IF the username field is not filled by the user.
Thank you.
P.S: Apologize if similar topics already exist, but I have looked'em up and couldn't find a straight answer for such a beginner.
Upvotes: 0
Views: 200
Reputation: 608
Can go for ternary
<div id="info"><?php echo (!empty(esc_attr( get_option('username') ))) ? esc_attr( get_option('username') ) : esc_attr( get_option('id') ); ?></div>
Upvotes: 2
Reputation: 4422
you dont need a function a simple if
else
will do your job
if(empty(get_option('username')) {
echo '<div id="info">'. esc_attr( get_option('username') ) . '</div>';
} else {
echo esc_attr( get_option('username') );
}
Upvotes: 2