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


Add http:// to ACF LINK

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

    • enky

    • February 15, 2019 at 9:46 pm


    maybe you try it with this

    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 🙂

  • 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.

    • enky

    • February 16, 2019 at 2:50 am


    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”;
    //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:

  • @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.