yvon Posted January 11, 2022 Share Posted January 11, 2022 (edited) 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 January 11, 2022 by yvon Quote Link to comment https://forums.phpfreaks.com/topic/314404-hide-text-if-echo-is-blank/ Share on other sites More sharing options...
gw1500se Posted January 11, 2022 Share Posted January 11, 2022 (edited) 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 January 11, 2022 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/314404-hide-text-if-echo-is-blank/#findComment-1593298 Share on other sites More sharing options...
ginerjm Posted January 11, 2022 Share Posted January 11, 2022 (edited) 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 January 11, 2022 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/314404-hide-text-if-echo-is-blank/#findComment-1593301 Share on other sites More sharing options...
gw1500se Posted January 11, 2022 Share Posted January 11, 2022 (edited) 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 January 11, 2022 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/314404-hide-text-if-echo-is-blank/#findComment-1593302 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.