Modify Link ACF Field value
-
Hello,
I would like to know if it’s possible to remove the base url of each internal links of my website from links fields.
Example, if I select an article in a link field : https://www.mywebsite.com/en/my-incredible-article
I would like to remove this part : https://www.mywebsite.com of the url when I save or even before saving.But I just want to do this for internal urls.
I tried this code but didn’t work :
add_filter(‘acf/format_value/type=link’, ‘remove_domain_from_link’, 20, 3);
function remove_domain_from_link($value, $post_id, $field) {
if (stripos($value, ‘company-name.com’) === false)) {
// value does not contain company-name.com
return $value;
}
$value = preg_replace(‘#^https?://[^/]*#’, ”, $value);
return $value;
}Thank you !
The topic ‘Modify Link ACF Field value’ is closed to new replies.