Jump to content

If statements with icon


Go to solution Solved by requinix,

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/316056-if-statements-with-icon/
Share on other sites

  • Solution

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.

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.