How to use a dynamic phone link?

I’m using ACF and storing a phone number in a post type. Let’s say the number in the text field looks like this: (123) 456-7890. I then imported the dynamic field on the page template with Bricks builder, but I need to change the dynamic link to remove all the special characters and spaces.

In the text link, I’ve done: tel:{acf_phone} with phone being the custom field. It’s returning: tel:(123) 456-7890. I need it to return, tel:1234567890.

How would you all recommend I implement something like this with Bricks?

1 Like

Did you ever find a solution to this?

function onnum ($num) {
	$num = '{' . $num . '}';
	$text = bricks_render_dynamic_data($num);
	return preg_replace( '/[^0-9]/', '', $text );
}
{echo:onnum(acf_tel)}
3 Likes

This appears to work in the builder, but not on the front end. I’ve flushed cache for this page and site wide, but still seeing the characters in the links. I’ve tested “tel:{mb_location_phone}” and it leaves the characters intact, whereas tel:{echo:onnum(mb_location_phone)} is stripping the characters.

I noticed this because I was seeing 404s for "/tel:636-671-7371

Any ideas?

Builder:

Front-end:

Did you add the “onnum” function to the list of allowed ones?

Thank you for your suggestion and the function.

It’s working now. It was a caching issue. I add another element with a loop to pull the same dynamic field, saved, then preview the page, then scoop off the appended preview characters in the URL, then purge cache on that page a couple times and finally it came about…then I just deleted the extra element.

Maybe it isn’t necessary, but I also added +1 before the number.

KC

Just make 2 fields:

  1. Phone number (text). Example of the field value: +7 123 456 78-90
  2. Link to the phone number (text). Link example: tel:71234567890

The first field is the dynamic tag for the text. The second field is a dynamic tag for the link.

You insert these tags where you need them and everything works :slightly_smiling_face: