Skip to content

Instantly share code, notes, and snippets.

@snrjosh
Last active March 22, 2024 16:41
Show Gist options
  • Save snrjosh/fd45aef7ccb30e61664459963a82e058 to your computer and use it in GitHub Desktop.
Save snrjosh/fd45aef7ccb30e61664459963a82e058 to your computer and use it in GitHub Desktop.
Force WPForms Modern Dropdown field to open downwards
<?php
// Filter: https://wpforms.com/developers/wpforms_field_select_choicesjs_config/
//Dropdown Style must be set to Modern, see: https://a.supportally.com/i/xJag2i
function wpf_dev_modern_dropdown_position_bottom( $config, $forms ) {
// Change 18591 to an ID of your actual form or remove this condition to apply to all forms.
// See: https://wpforms.com/developers/how-to-locate-form-id-and-field-id/#form-id
if ( ! array_key_exists( 18591, $forms ) ) {
return $config;
}
//Configure Dropdown field to always open downwards
//Default is 'auto'. Can set to 'top' (https://github.com/Choices-js/Choices#position)
$config['position'] = 'bottom';
return $config;
}
add_filter( 'wpforms_field_select_choicesjs_config', 'wpf_dev_modern_dropdown_position_bottom', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment