Support

Account

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;
    }