Support

Account

Home Forums Backend Issues (wp-admin) Add http:// to ACF LINK

Solved

Add http:// to ACF LINK

  • Hi,
    is it possible to automatically prefill ACF link with http:// ?
    thankqs

    • enky

    • February 15, 2019 at 9:46 pm

    Hi,

    maybe you try it with this

    https://www.advancedcustomfields.com/resources/acf-prepare_field/

    
    function my_acf_prepare_field( $field ) {
      $field['value']['url'] = "https";
      return $field;
    }
    
    add_filter('acf/prepare_field/key=field_5c6691766a1c2', 'my_acf_prepare_field');
    
    

    You only need to validate, if there is already a “good” url saved.

    Or you take a look here, and find yourself another filter 🙂

    https://www.advancedcustomfields.com/resources/#filters

  • thanks, why using [url] and not this ?
    $field[‘value’] = ‘https//’;

    and the problem is that replace the existing content, i need that add ‘https’ only if the field is empty.
    thanks

    • enky

    • February 16, 2019 at 2:50 am

    Hi,

    i used $field[‘value’][‘url’] = “https”; because in my quck test it seems right.

    And the other Problem, yeah, thats what i meant with

    “if there is already a “good” url saved.”

    You have to validate inside the function if $field[‘value’][‘url’] is already a valid url.

    Should be something like these

    if($field[‘value’][‘url’] != valid url){
    //no valid url, fill the field with https/http
    $field[‘value’][‘url’] = “https”;
    }else{
    //already a valid url here, nothing to do
    }

    return $field;

    Sry, im not a php developer, but if you google for “php validate url” you should find something, thats fit.

    I think this could work here: https://stackoverflow.com/questions/7003416/validating-a-url-in-php

  • @pipoulito You might try entering https:// as the default value and placeholder for a link in the field group editor, rather than this JS solution after the fact.

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

You must be logged in to reply to this topic.

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.