Last active
August 29, 2015 14:21
-
-
Save tripflex/8dd22c6a3b7472ec3461 to your computer and use it in GitHub Desktop.
Output twitter link from username
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$twitter_username = get_custom_field('company_twitter'); | |
if( ! empty( $twitter_username ) ) { | |
$clean_twitter = sanitize_text_field( $twitter_username ); | |
// Check for http: or https: in $clean_twitter | |
if ( $clean_twitter && ! strstr( $clean_twitter, 'http:' ) && ! strstr( $clean_twitter, 'https:' ) ) { | |
// Check if twitter.com is not in string (means they used username only) | |
if( ! strstr( $clean_twitter, 'twitter.com' ) ){ | |
$clean_twitter = "https://twitter.com/{$clean_twitter}"; | |
} else { | |
$clean_twitter = 'http://' . $clean_twitter; | |
} | |
} | |
echo "<a href=\"{$clean_twitter}\"><img src=\"//yourdomain.com/twitter-icon.png\"></a>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment