gistfile1.phtml
<?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>";
}
No comments yet.