Remove all characters from a string for a clean phone number link
Posted on
If a user is entering a phone number via an admin section, and you want to be able to hit that with some regex in order to turn it into a valid link. This example is using the “get_field” from the ACF api, but you can reference your variable how ever you’d like.
|*|-php-|*|
<a href="tel:'.preg_replace("/[^0-9]/","",esc_attr( get_field('phone_number'))).'">'.esc_attr( get_field('phone_number') ).'</a></span>