Home Forums General Issues URL Field – tel: link rather than http:


URL Field – tel: link rather than http:

  • I’ve submitted this support ticket (hoping to get some advice soon) but thought the question maybe useful to the wider community as well…

    I’m new to your plugin (like it so far and using the current version) but I’m got a brick wall with the ‘URL’ field type.

    When I enter my ‘link’, which is a tel: link rather than http: or such like, I get an error message ‘Value must be a valid URL error’ and I can’t publish the post.

    I’m using what I believe to be the correct href syntax, i.e. <a href="tel:+1-201-555-0111">(201) 555-0111</a> which I got from rfc3966 and I’ve tried entering it into the field in these variations:

    <a href="tel:+1-201-555-0111">(201) 555-0111</a>
    href="tel:+1-201-555-0111">(201) 555-0111
    <a href="tel:+1-201-555-0111">

    None of these work, and I’m out of ideas!

    I have another WP site that I’m using the normal link dialogue to use a tel:+1-201-555-0111 link and it works perfect, the validation error only seems to be via your plugin.

    I would appreciate any ideas please.

    Many thanks

  • The URL will only take a web page URL and there isn’t a way to alter this.

    I use the following to add a setting to use text field an validate

      add_action('acf/render_field_validation_settings/type=text', 'validate_text_as_href_setting');
      add_action('acf/validate_value/type=text', 'validate_text_as_href', 10, 4);
      function validate_text_as_href_setting($field) {
        // this adds a setting to text fields
        // setting it to true will require that the content of the fields
        // meets requirements to be used as a link href value
        $args = array(
          'label' => 'Validate as HREF',
          'instructions' => 'Require a valid href attribute. This includes values starting with: http://, https://, ftp://, mailto:, tel:, sms:, /, and #',
          'type' => 'true_false',
          'name' => 'validate_href',
          'ui' => 1,
          'class' => ''
        acf_render_field_setting($field, $args);
      function validate_text_as_href($valid, $value, $field, $input) {
        // if the setting created by validate_text_as_href_setting
        // is true than this filter will test input to ensure it can
        // be used in as a link href value
        // this allows links starting with
        // / (site root relative), http://, https://, ftp://, # (anchor), mailto:, tel:, sms:
        if (!$valid) {
          return $valid;
        // does setting exist and is it set
        if (!empty($field['validate_href'])) {
          // only validate if value submitted (use acf required setting to require value)
          if (!empty($value)) {
            // allow anything that looks like a valid href value
            if (!preg_match('%^(https?\://|ftp\://|/|#|mailto\:|sms\:|tel\:)%', $value)) {
              $valid = 'Enter a Valid Link HREF Value';
        return $valid;
  • Hi @hube2 John,

    Thank you very much for the reply. Could you give me a clue as to where in WordPress or ACF that I would use this php script please?

    PS – Love your avatar of the golden eagle!

    Many thanks

  • You would put this in your child theme functions.php file.

  • Hey @hube2

    I’ve got that in my functions.php and can now see it in the ACF field settings, and I can add it to my custom post type but…

    I’m adding it to a button element in Elementor and although the button works as a link it displays the link text as the button text.

    Knowing zero about php, I assume there is a way to add an attribute to the script so that I can input link text to be displayed rather than default to the link itself?

    As an aside, the ACF support came back to and said to use the Link rather than URL field type in the Field Group. Although this works nicely to allow me to add the link to the custom post in a normal WP way, including having the option for the URL and link text that I’m looking for… I can find no way to add this new Link field as a dynamic element in Elementor, as that Link field just does not show as a dynamic field available to me. I’ve gone back to them, but currently your scripted suggestion is providing me the most progress.

  • This will not work in elementor. I was assuming you were creating code to show the URL field. What you want to do cannot be done in elementor without writing custom code.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.