Fix replace function for custom fields