Title: Excluding Java-Code
Last modified: April 12, 2025

---

# Excluding Java-Code

 *  Resolved [Chigolo](https://wordpress.org/support/users/fitnsexy/)
 * (@fitnsexy)
 * [1 year ago](https://wordpress.org/support/topic/excluding-java-code/)
 * Hello,
   I’m having an issue with WPFORMS related to minifying Java files.I’d like
   to prevent the Enter key from submitting my forms, but unfortunately, the snippet
   code isn’t being executed due to minification. Is there a way to exclude this?
 *     ```wp-block-code
       /** * Disable the Enter key WPForms forms * * @link https://wpforms.com/developers/how-to-stop-the-enter-key-from-submitting-the-form/ */ function wpf_dev_disable_enter_all_wpforms( ) { ?> <script type="text/javascript"> // Run this snippet on all WPForms forms jQuery( 'form.wpforms-form' ).bind( 'keypress keydown keyup', function(e) { if (e.keyCode == 13) { e.preventDefault(); } }); </script> <?php } add_action( 'wpforms_wp_footer_end', 'wpf_dev_disable_enter_all_wpforms', 30 );
       ```
   

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Support [Damilare](https://wordpress.org/support/users/deabiodun/)
 * (@deabiodun)
 * [12 months ago](https://wordpress.org/support/topic/excluding-java-code/#post-18414539)
 * Hi [@fitnsexy](https://wordpress.org/support/users/fitnsexy/)!
   The best way to
   exclude the code script is by enqueuing it as an external script using wp_enqueue_script.
   For example, you can have your code in _**wp-content/uploads/my\_files/my\_script.
   js**_. Then, using _**wp\_enqueue\_script()**_ as described below, your custom
   external script will be applied to the footer section of your site
 * `function enqueue_custom_jquery_script() {
    $script_url = content_url('uploads/
   my_files/my_script.js'); wp_enqueue_script('my-custom-script', $script_url, array('
   jquery'), null, true );}add_action('wp_enqueue_scripts', 'enqueue_custom_jquery_script');
 * With that, you can exclude your JavaScript file by adding _**wp-content/uploads/
   my\_files/my\_script.js**_ to the _**Exclude JavaScript from processing**_ field
   at **WP-Optimize > Minify > JavaScript**.
 * With that, your forms should work as expected.
 * Let us know if that works for you.
 * Regards.
 *  Thread Starter [Chigolo](https://wordpress.org/support/users/fitnsexy/)
 * (@fitnsexy)
 * [12 months ago](https://wordpress.org/support/topic/excluding-java-code/#post-18414844)
 * Thx [@deabiodun](https://wordpress.org/support/users/deabiodun/)
 * Where do I have to enter the code above?
 *     ```wp-block-code
       function enqueue_custom_jquery_script() {$script_url = content_url('uploads/my_files/my_script.js');wp_enqueue_script('my-custom-script', $script_url, array('jquery'), null, true );}add_action('wp_enqueue_scripts', 'enqueue_custom_jquery_script');
       ```
   
 *  Plugin Support [Damilare](https://wordpress.org/support/users/deabiodun/)
 * (@deabiodun)
 * [12 months ago](https://wordpress.org/support/topic/excluding-java-code/#post-18416034)
 * You can use a code snippet plugin or paste it in your themes functions.php file.
 * Note that you could loose the code with the theme approach, when the theme gets
   updated. So consider using a child theme.
 * Regards.
 *  Thread Starter [Chigolo](https://wordpress.org/support/users/fitnsexy/)
 * (@fitnsexy)
 * [12 months ago](https://wordpress.org/support/topic/excluding-java-code/#post-18416508)
 * Allright, thx for your support [@deabiodun](https://wordpress.org/support/users/deabiodun/)
 *  Thread Starter [Chigolo](https://wordpress.org/support/users/fitnsexy/)
 * (@fitnsexy)
 * [12 months ago](https://wordpress.org/support/topic/excluding-java-code/#post-18416521)
 * If anyone is interested, I created a JS file with the following code:
 *     ```wp-block-code
       /** * Disable the Enter key WPForms forms * * @link https://wpforms.com/developers/how-to-stop-the-enter-key-from-submitting-the-form/ */jQuery(function($) {    $('form.wpforms-form').on('keydown', function(e) {        if (e.key === 'Enter') {            e.preventDefault();        }    });});
       ```
   
 * and placed it in a “custom-js” folder in my theme, then created a snippet like
   this:
 *     ```wp-block-code
       /** Disable the Enter key WPForms forms */function wpf_enqueue_disable_enter_script() {    // Prüfen, ob WPForms aktiv ist    if (function_exists('wpforms')) {        // Script registrieren und laden        wp_enqueue_script(            'wpf-disable-enter', // Handle            get_template_directory_uri() . '/custom-js/wpforms_disable-enter.js', // Pfad zur JS-Datei            ['jquery'], // Abhängigkeit            null, // Version (optional)            true // Im Footer laden        );    }}add_action('wp_enqueue_scripts', 'wpf_enqueue_disable_enter_script');
       ```
   

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Excluding Java-Code’ is closed to new replies.

 * ![](https://ps.w.org/wp-optimize/assets/icon-256x256.png?rev=1552899)
 * [WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance](https://wordpress.org/plugins/wp-optimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-optimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-optimize/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-optimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-optimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-optimize/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [Chigolo](https://wordpress.org/support/users/fitnsexy/)
 * Last activity: [12 months ago](https://wordpress.org/support/topic/excluding-java-code/#post-18416521)
 * Status: resolved