Last active
July 20, 2016 14:29
-
-
Save celticwebdesign/7414270e55159a3b0b01 to your computer and use it in GitHub Desktop.
Read options telephone number and make it international for mobile devices.
This file contains hidden or 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 | |
function click_telephone($telephone, $string = null, $prepend = null, $prepend_zero = null) { | |
/* | |
Parameters: | |
$telephone - string, the actual number | |
$string - string, if you want to dispay a clickable strong rather than telephone number, | |
$prepend - string, prepend the telephone number. | |
$countrycode - string, country code or default UK 0044 | |
*/ | |
$ori_tel = str_replace( ' ', '', $telephone ); | |
$new_tel = "0044".substr($ori_tel, 1); | |
$output = "<a href='tel:".$new_tel."' class='tel'>"; | |
if( $string ) {$output.=$string;} | |
else { | |
if($prepend) { | |
$output.=$prepend." "; | |
} | |
if($prepend_zero == true) { | |
$output.="0"; | |
} | |
$output.=substr($ori_tel, 1); | |
} | |
$output .= "</a>"; | |
return $output; | |
} | |
echo click_telephone( get_field('options_mobile', 'option') ); | |
or | |
echo click_telephone( get_field('options_telephone', 'option'), '<i class="fa fa-phone"></i>', 'UK: +44', true ); | |
of | |
echo click_telephone( get_field('footer_phone_number', 'option'), null, null, null, null ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment