• Resolved hkeely

    (@hkeely)


    Hi! I’m trying to set it so that when a user comes to my homepage, the site auto-focuses the keyboard on the search field when the page is loaded, without the user having to click anywhere on the field at all. The idea is they they can just start typing to search, with no initial click. How can we get that to happen?

    Thank you for your help!

    Site: https://www.harrisonsresearcher.com

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi,

    You will need to custom code that unfortunately. It should not be too difficult though, I might be able to suggest something.

    Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

    add_action("wp_footer", "asp_custom_script_wp_footer");
    function asp_custom_script_wp_footer() {
    	?>
    	<script>
    	jQuery(function($){
    	    setTimeout(function() {$('input.orig').focus();}, 1000);
    	});
    	</script>
    	<?php
    }

    Best,
    Ernest M.

    Thread Starter hkeely

    (@hkeely)

    That works perfectly! Thank you so much, Ernest!!

    I absolutely love Ajax Search. It’s what makes my site possible.

    Great work!

    Thread Starter hkeely

    (@hkeely)

    Oh no – it works great on the homepage, but on every other page it’s jumping users to the bottom of the page (where I have a second search box). How can I implement the focus so it’s only on the homepage, or uses only the search box in the header of each page?

    Thread Starter hkeely

    (@hkeely)

    Hooray! I figured it out! Thank you again for your help, Ernest!

    Thread Starter hkeely

    (@hkeely)

    Oh, and for anyone else who may have a similar issue, the code I used was:

    add_action("wp_footer", "asp_custom_script_wp_footer");
    function asp_custom_script_wp_footer() {
    	?>
    	<script>
    	jQuery(function($){
    	    setTimeout(function() {$('form:first *:input[type!=hidden]:first').focus();}, 1000);
    	});
    	</script>
    	<?php
    }
    • This reply was modified 3 years, 11 months ago by hkeely.
    Plugin Author wpdreams

    (@wpdreams)

    That is superb ??

    If you don’t mind I will mark this topic as resolved then.

    Feel free to rate the plugin, it is greatly appreaciated ?? Thank you!

    Best,
    Ernest M.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to auto focus users on search field with no click’ is closed to new replies.