Skip to content

Instantly share code, notes, and snippets.

@eolant
Last active March 24, 2021 10:46
Show Gist options
  • Save eolant/d94a0f45b275b781bb05c51ea165eff4 to your computer and use it in GitHub Desktop.
Save eolant/d94a0f45b275b781bb05c51ea165eff4 to your computer and use it in GitHub Desktop.
Contact form 7 Bootstrap 4 custom radio and checkbox buttons filter to remove spans and change HTML structure
/**
* Adjust contact form 7 radios and checkboxes to match bootstrap 4 custom radio structure.
*/
add_filter('wpcf7_form_elements', function ($content) {
$content = preg_replace('/<label><input type="(checkbox|radio)" name="(.*?)" value="(.*?)" \/><span class="wpcf7-list-item-label">/i', '<label class="custom-control custom-\1"><input type="\1" name="\2" value="\3" class="custom-control-input"><span class="wpcf7-list-item-label custom-control-label">', $content);
return $content;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment