Skip to content

Instantly share code, notes, and snippets.

@celticwebdesign
Last active July 20, 2016 14:29
Show Gist options
  • Save celticwebdesign/7414270e55159a3b0b01 to your computer and use it in GitHub Desktop.
Save celticwebdesign/7414270e55159a3b0b01 to your computer and use it in GitHub Desktop.
Read options telephone number and make it international for mobile devices.
<?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