Warning: Use of undefined constant DATABASE_SERVER - assumed 'DATABASE_SERVER' (this will throw an Error in a future version of PHP) in /nfs/c12/h06/mnt/224893/domains/markszymanski.com/html/wp-config.php on line 31
Remove all characters from a string for a clean phone number link – Mark Szymanski

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

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 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.