Posted in PHP

Format any phone number into an international URL

A lot of the time a phone number is entered into an ACF text field which needs to be clickable. Formatting the entire phone number would remove the pretty syntax the user likes to add, yet if it is not formatted the number often wouldn’t work well when added in an anchor tag.

For this reason we are stripping the added information to use in a link behind the scenes, while still keeping the number nice and pretty on the front end for the user.
In the below example we are formatting UK phone numbers. You would need to replace the +44 country code for whichever is required.

Leave a Reply

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