oinic Posted March 27, 2023 Share Posted March 27, 2023 Hi guys im still trying to edit a wp with php. that my situation: <div class="col-md-4"> <div class="item"> <div class="img"><img src="<?php echo wp_kses_post($item['tab_image']['url']); ?>" alt=""></div> <div class="info"> <h5><?php print wp_kses_post($item['name']); ?></h5> <h6><?php print wp_kses_post($item['info']); ?></h6> <div class="social valign"> <div class="full-width"> <a href="callto:<?=$item['phone']; ?>"><i class="fa fa-phone"></i></a> <a href="mailto:<?=$item['email']; ?>"><i class="fa fa-envelope"></i></a> <a href="<?php print wp_kses_post($item['linkedin']); ?>"><i class="fab fa-linkedin-in"></i></a> </div> </div> </div> </div> </div> <?php endforeach; ?> </div> to know if a field is empty or not the field in elementor must be empty or not so i would like to use a if else statements but i dont know how to do it Someone has an idea? thx Quote Link to comment https://forums.phpfreaks.com/topic/316056-if-statements-with-icon/ Share on other sites More sharing options...
requinix Posted March 27, 2023 Share Posted March 27, 2023 Don't know what an "elementor" is... You have decided that you need an if/else to solve a problem. What is the problem itself? What field, and why do you need to know if it's empty? Quote Link to comment https://forums.phpfreaks.com/topic/316056-if-statements-with-icon/#findComment-1606882 Share on other sites More sharing options...
oinic Posted March 27, 2023 Author Share Posted March 27, 2023 Sorry i want to know if there is for example a link( a linkedin from a user) inside the fab fa linkedin , if not i would like that the icon is hidden, i try but doesnt work. I hope that explain better the situation, thx you Quote Link to comment https://forums.phpfreaks.com/topic/316056-if-statements-with-icon/#findComment-1606884 Share on other sites More sharing options...
oinic Posted March 27, 2023 Author Share Posted March 27, 2023 I would like to know if is empty because i prefer to not show an icon if is unclickable (it doesnt redirect if is there is not a link inside) Quote Link to comment https://forums.phpfreaks.com/topic/316056-if-statements-with-icon/#findComment-1606885 Share on other sites More sharing options...
Solution requinix Posted March 27, 2023 Solution Share Posted March 27, 2023 So with this, <a href="<?php print wp_kses_post($item['linkedin']); ?>"><i class="fab fa-linkedin-in"></i></a> the link is wp_kses_post(...) and you don't want to show the <a> if the link is empty. Get the value of the link into a variable, use it with the if statement, then only show the <a> if not empty. <?php $linkedinlink = wp_kses_post($item['linkedin']); if ($linkedinlink) { printf('<a href="%s"><i class="fab fa-linkedin-in"></i></a>', htmlspecialchars($linkedinlink)); } ?> Remember to use htmlspecialchars when you do not know if a value is 100% safe for HTML. Quote Link to comment https://forums.phpfreaks.com/topic/316056-if-statements-with-icon/#findComment-1606886 Share on other sites More sharing options...
oinic Posted March 27, 2023 Author Share Posted March 27, 2023 Thank you for your answer i will try later, yep im new on php and I have a lot things to understand but i will save your suggestion😀 Quote Link to comment https://forums.phpfreaks.com/topic/316056-if-statements-with-icon/#findComment-1606887 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.