Support

Account

Home Forums Backend Issues (wp-admin) Phone field with href="tel:" link Reply To: Phone field with href="tel:" link

  • Use a format value filter

    2 fields

    
    add_filter('acf/format_value/name=phone_field', 'convert_phone_to_link', 20, 3);
    function convert_phone_to_link ($value, $post_id, $field) {
      if (!$value) {
        // no value
        return $value;
      }
      // get the tel link field
      $tel_link = get_field('tel_link_field')
      if (!$tel_link) {
        // no link
        return $value;
      }
      $value = '<a href="tel:'.$tel_link.'">'.$value.'</a>';
      return $value;
    }
    

    1 field

    
    add_filter('acf/format_value/name=phone_field', 'convert_phone_to_link', 20, 3);
    function convert_phone_to_link ($value, $post_id, $field) {
      if (!$value) {
        // no value
        return $value;
      }
      // assumes US number
      $tel_link= '+1'.preg_repace('/[^0-9]/', '', $value);
      $value = '<a href="tel:'.$tel_link.'">'.$value.'</a>';
      return $value;
    }