Plugin Support
oiler
(@eulerarthur)
Hey @jalorod,
Thanks for your contact!
You’re right – by default, Pretty Links only validates standard URLs (with http://, https://, etc.) and mailto: links, so tel: URIs get rejected by the validation. It’s not a bug per se, but it’s definitely a gap we’re aware of.
That said, you can get this working with a small code snippet. If you install the free WPCode plugin, go to WPCode -> Snippets, create a new PHP snippet and paste this:
/**
* Add tel: URI Support to Pretty Links
*/
function prli_support_tel_uris($is_valid) {
$url = '';
if (isset($_POST['url'])) {
$url = sanitize_text_field($_POST['url']);
} elseif (isset($_REQUEST['target_url'])) {
$url = sanitize_text_field($_REQUEST['target_url']);
}
if (empty($url) || $is_valid) {
return $is_valid;
}
if (preg_match('/^tel:(?:\+)?[\(]?[0-9][0-9\-\.\s\(\)]*[0-9]$/', $url)) {
return true;
}
return $is_valid;
}
add_filter('prli_is_valid_url', 'prli_support_tel_uris', 10);
Once activated, you’ll be able to use phone numbers like tel:+12026952128 or tel:123-456-7890 as your target URL. So creating a Pretty Link like https://website.com/call that redirects to tel:123456789 will work, and clicks will be tracked as usual.
One thing to keep in mind – make sure parameter forwarding is set to “Off” on your tel: links (it’s off by default, so unless you changed this option, it you should be fine). Otherwise Pretty Links would append query strings to the phone number, which would break the dialer.
Feel free to let me know if you run into any issues with it. Thanks!
All the best,
Euler.
Thank you for your answer. I am employing your workaround with success.
Although it would be great to support this type of links in future versions directly.
Thank you!
Plugin Support
oiler
(@eulerarthur)
Hi there,
Glad that it is fine now! Also, thanks for your feedback, I will ensure to share it internally.
In this case, I hope we are good to close here, but please feel free to contact us anytime if you need assistance with our products.
Kind regards,