Home / Admin / Add Autofocus on Your Form
Duplicate Snippet

Embed Snippet on Your Site

Add Autofocus on Your Form

This snippet adds auto focus to the first field of your form when the page loads.

Code Preview
Add autofocus to the first form field of the form
Original doc link: https://wpforms.com/developers/how-to-add-autofocus-on-your-form/
For support, please visit: https://www.facebook.com/groups/wpformsvip
function wpf_dev_autofocus() {
<script type="text/javascript">
    jQuery(document).ready(function() {
        var first_input = jQuery( 'form.wpforms-form input[type=text]:visible:enabled:first, textarea:visible:enabled:first' )[0];
        if (first_input != undefined) {
add_action( 'wpforms_wp_footer_end', 'wpf_dev_autofocus', 10 );


Add a Comment