Last active
July 25, 2022 13:11
-
-
Save marklchaves/bb09fcbba6c454edf42eada97120e449 to your computer and use it in GitHub Desktop.
Force the focus on the name field in a CF7 form
This file contains 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 // Ignore this first line when copying to your child theme's functions.php file. | |
<style> | |
/** For testing only. Remove for production. */ | |
:focus { | |
outline: 3px solid hotpink !important; | |
} | |
</style> | |
<script type="text/javascript"> | |
jQuery(document).ready(function ($) { | |
const popupID = 1749; // Change to your popup ID. | |
$(document).on('pumAfterOpen', `#pum-${popupID}`, function () { | |
$('.pum-content.popmake-content input.cf7-name').focus(); // Change .cf7-name to your input field selector. | |
}); // listener | |
}); // jQuery | |
</script> | |
<?php } | |
add_action( 'wp_footer', 'force_focus_on_name_field', 500 ); // Load the script in the footer with a "late" priority. | |
/** | |
* You can add the PHP code snippet to your child theme's functions.php file | |
* or with third-party plugins such as My Custom Functions and Code Snippets. | |
* | |
* Learn more: | |
* - https://docs.wppopupmaker.com/article/84-getting-started-with-custom-js | |
* - https://docs.wppopupmaker.com/article/552-getting-started-with-custom-php | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment