Created
October 13, 2025 19:12
-
-
Save rickalday/f549ee8ce8c4370f4a87c9768e746f3f to your computer and use it in GitHub Desktop.
Make the first element of a GiveWP dropdown element non-selectable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_action("givewp_donation_form_enqueue_scripts", function () { | |
| ?> | |
| <script> | |
| document.addEventListener("DOMContentLoaded", function () { | |
| // Run after a short delay to ensure UI is ready | |
| setTimeout(() => { | |
| //Assuming your select element has an name of 'favorite_color' | |
| const selectElement = document.querySelector('select[name="favorite_color"]'); | |
| // Get the first option element | |
| const firstOption = selectElement.options[0]; | |
| // Make the first option non-selectable | |
| firstOption.disabled = true; | |
| }, 100); // small delay to let GiveWP UI finish rendering | |
| }); | |
| </script> | |
| <?php | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment