the_toolman Posted July 13, 2019 Share Posted July 13, 2019 Hi, I have the following code in a WordPress theme which displays a companies website, Twitter and Facebook links. What I am trying to do is display the text "Useful Links:" if one of the links exists, and hide the text if all are not present. <p>Useful Links:</p> <?php if ( $website = get_the_company_website() ) : ?> <a class="company-website" href="<?php echo esc_url( $website ); ?>" itemprop="url" target="_blank" rel="nofollow"><?php _e('Website', 'jobseek'); ?></a> <?php endif; ?> <?php if ( get_the_company_twitter() ) : ?> <a class="company-twitter" href="http://twitter.com/<?php echo get_the_company_twitter(); ?>" target="_blank"><?php _e('Twitter', 'jobseek'); ?></a> <?php endif; ?> <?php $facebook_link = get_post_meta( get_the_ID(), '_facebook_link', true ); if ( ! empty($facebook_link) ) : ?> <a class="company-facebook" href="<?php echo $facebook_link; ?>" target="_blank">Facebook</a> <?php endif; ?> What would be the best way to show/hide the text depending on if the items are present or not? Thanks Quote Link to comment Share on other sites More sharing options...
Barand Posted July 13, 2019 Share Posted July 13, 2019 Perhaps something like $links['company_website'] = get_the_company_website(); $links['company_twitter'] = get_the_company_twitter(); $links['company_facebook'] = get_post_meta( get_the_ID(), '_facebook_link', true ); foreach (array_filter($links) as $cls = $link) { // output link } Quote Link to comment Share on other sites More sharing options...
the_toolman Posted July 14, 2019 Author Share Posted July 14, 2019 Thanks for the reply, I will try that Quote Link to comment 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.