Skip to content

Instantly share code, notes, and snippets.

@Acephalia
Last active December 14, 2023 22:36
Show Gist options
  • Save Acephalia/66c02add6f7df5cf3a06542b9a7168b7 to your computer and use it in GitHub Desktop.
Save Acephalia/66c02add6f7df5cf3a06542b9a7168b7 to your computer and use it in GitHub Desktop.
Remove/replace "https://" from ACF URL field output
// Remove "https://" from ACF URL field output
function sanitize_acf_url_output($value, $post_id, $field) {
if ($field['type'] === 'url') {
// Remove "https://" from the URL
$value = str_replace('https://', '', $value);
}
return $value;
}
add_filter('acf/format_value/type=url', 'sanitize_acf_url_output', 10, 3);
// Replace "https://" with "www." in ACF URL field output
function modify_acf_url_output($value, $post_id, $field) {
if ($field['type'] === 'url') {
// Replace "https://" with "www."
$value = str_replace('https://', 'www.', $value);
}
return $value;
}
add_filter('acf/format_value/type=url', 'modify_acf_url_output', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment