Home › Forums › Backend Issues (wp-admin) › Phone field with href="tel:" link › Reply To: Phone field with href="tel:" link
Hey ACF/Elementor Friends 🙂
Here are some snippets that are working on my client’s site:
PHONE MAILTO
// Convert Mobile to tel link
add_filter('acf/format_value/name=ACF_MOBILE_FIELD_NAME', 'convert_phone_to_link', 20, 3);
function convert_phone_to_link ($value, $post_id, $field) {
if (!$value) {
return $value;
}
$tel_link = preg_replace('/[^0-9]/', '', $value);
$value = '<a href="tel:'.$tel_link.'">'.$value.'</a>';
return $value;
}
EMAIL MAILTO
// Convert Email to mailto link
add_filter('acf/format_value/name=ACF_EMAIL_FIELD_NAME', 'convert_email_to_link', 20, 3);
function convert_email_to_link ($value, $post_id, $field) {
if (!$value) {
return $value;
}
$email_link = $value;
$value = '<a href="mailto:'. $email_link .'">'. $value .'</a>';
return $value;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.