Home › Forums › Backend Issues (wp-admin) › Add http:// to ACF LINK
Hi,
is it possible to automatically prefill ACF link with http:// ?
thankqs
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
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.
The topic ‘Add http:// to ACF LINK’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.