Jump to content

Hide text if echo is blank


yvon
 Share

Recommended Posts

Hello

Im a newbie on php but i like to change a small part of the code.

<p><strong>telefoon:</strong> <?php  echo get_the_author_meta('telefoon', $curauthID); ?></p>

I would like to hide telefoon: if the echo command get_the_autor_meta is empty

Edited by yvon
Link to comment
Share on other sites

First please use the code icon (<>) at the top of the menu for your code and specify PHP.

<?php
$tele=get_the_author_meta('telefoon', $curauthID);
attrib=""
if (empty($tele)){
   $attrib="hidden"
}
echo "<p $attrib><strong>telefoon:</strong>$tele</p>";
?>

Untested.

Edited by gw1500se
Link to comment
Share on other sites

FYI - the code above is missing a couple of semicolons

Note how the code was written without leaving PHP mode and thus avoids the messy way of having to code your p tag so clumsily.  

AND - if this is not the sole contents of your php script then leave out the ?> tag.  It is not required nor is it needed to end a script.  Entering and leaving php mode is not a practical way of coding a php script.  Sure - you may have some block of JS code so you can do it but when all you are doing is running php logic and then assembling php results with html code use the echo and double quotes and avoid the in-and-out style of coding php results.  Just my $.02

Edited by ginerjm
Link to comment
Share on other sites

39 minutes ago, gw1500se said:
<?php
$tele=get_the_author_meta('telefoon', $curauthID);
$attrib="";
if (empty($tele)){
   $attrib="hidden";
}
echo "<p $attrib><strong>telefoon:</strong>$tele</p>";
?>

 

Sorry. Corrected code.

Edited by gw1500se
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.