Tell us what you are trying to do?
Display a phone number as a link.
I am using a "phone" custom field.
I want the diplayed number be something like +43 123 456 78.
Basically i want this: +43 123 456 78
How can i achive that? Do i need 2 custome fields - one for the "pretty" number and one for the link?
Or is there a better way to achive that?
Thanks,
Daniel
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Well - you can enable the legacy view's if its not eanabled. Please check the following Doc:
=> https://toolset.com/course-lesson/enabling-legacy-version-of-toolset-views/
After that - you can add "Fields and Text" block or shortcodes block if you are using blocks and add the following to it:
<a href="tel:[types field='phone-field-slug'][/types]">[types field='phone-field-slug'][/types]</a>
Hi Menish,
thanks!
So this shortcode stripe empty spaces in the number when adding the link, right?
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
It will not strip the empty spaces it will display the number filed value as you submitted in backend.
But this means, i would have to enter the number in the phone-field without empty spaces?
Or is this not a problem and it will work with empty spaces like +43 676 123 456 67 ?
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
If you want to keep space and plus sign (+43) then you will have to use the normal "single line" custom field instead of number field. Single field will allow you to add plus sign as well as space and numbers.
So instead of phone type custom field you should conver this field to "single line" field.
But i do have this format in my phone field right now: +43 676 123 456 67
The question is: If this value is now output in the short code as
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
You should first try the solution I shared and check:
<a href="tel:[types field='phone-field-slug'][/types]">[types field='phone-field-slug'][/types]</a>
It should work.
Sorry, my previous message got cut off.
Yes, of course I tried the shortcode.
I noticed that the phone number I entered – with spaces for better readability – is also rendered with spaces inside the href of the
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
For that - you will have to write the custom shortcode - you can add the following shortcode to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/
function remove_all_spaces_shortcode($atts, $content = null) {
if ($content === null) return '';
// Remove all whitespace (left, right, and middle)
$trimmed = preg_replace('/\s+/', '', $content);
return $trimmed;
}
add_shortcode('remove_spaces', 'remove_all_spaces_shortcode');
And call this shortcode as:
[remove_spaces][types field='phone-field-slug'][/types][/remove_spaces]
Thanks! That's what i was looking for!