Jump to content

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
https://forums.phpfreaks.com/topic/314404-hide-text-if-echo-is-blank/
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

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
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
This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.