Design & Development

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>
Published under: Snippets
Tags: ,
Previous business-address

WP Plugin Business Address

Next Print design example

An example of bringing some print text design to the web

Leave a Reply

Your email address will not be published. Required fields are marked *