Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Set focus mouse
This topic contains 6 replies, has 2 voices, and was last updated by Ernest Marcinko 2 years, 6 months ago.
- AuthorPosts
- November 25, 2020 at 2:18 pm #30352
dear Ernest,
i wondered if you could suggest how to make the focus of the keyboard automatically set on the Ajax Search Pro bar when my site loads up?
I found this article (with you offering solutions in it!) on wordpress.org
https://wordpress.org/support/topic/trying-to-automatically-set-focus-in-the-search-box/For my site, the search is the main feature – to find a catalog of 900 pages.
BTW your plugin, which I bought the full version today) is just amazing. It has solved many of my problems. That combined with a WP Sheet Editor Spreadsheet is just the most incredibly sophisticated search database.
Any help would be appreciated.
-
This topic was modified 2 years, 6 months ago by
joolsscott84.
November 25, 2020 at 2:28 pm #30353Hi,
Thank you for the details!
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> var inv; jQuery(function($){ inv = setInterval(function() { if ( typeof ASP != "undefined" && ASP.initialized ) { $('input.orig').focus(); clearInterval(inv); } }, 500); }); </script> <?php }
I could not test this, so please be careful.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
November 25, 2020 at 2:34 pm #30355You are amazing! that worked first time.
I will make a child theme so it doesn’t get lost when i update.
Many thanks Ernest. I will leave a review on WP and CC
November 25, 2020 at 2:37 pm #30356One last thing (upon testing)
Can you think of any way to make this work only on the homepage?
i have a search box on each post and this new code currently takes the focus to the bottom of the page.
Thanks again
November 25, 2020 at 2:48 pm #30358You are welcome, and thank you for your kind words. Maybe, I think the is_home() might do it.
Best,add_action("wp_footer", "asp_custom_script_wp_footer"); function asp_custom_script_wp_footer() { if ( is_home() ) { ?> <script> var inv; jQuery(function($){ inv = setInterval(function() { if ( typeof ASP != "undefined" && ASP.initialized ) { $('input.orig').focus(); clearInterval(inv); } }, 500); }); </script> <?php } }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
November 25, 2020 at 2:54 pm #30361That seems to have broken the script, it doesn’t work on home either now.
Sorry to take up your time!
If we can’t work it out I will go back to how it was originally.
Thanks Ernest! Really appreciate your help
November 25, 2020 at 2:58 pm #30363Maybe this variation then:
Best,add_action("wp_footer", "asp_custom_script_wp_footer"); function asp_custom_script_wp_footer() { if ( is_front_page() ) { ?> <script> var inv; jQuery(function($){ inv = setInterval(function() { if ( typeof ASP != "undefined" && ASP.initialized ) { $('input.orig').focus(); clearInterval(inv); } }, 500); }); </script> <?php } }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
-
This topic was modified 2 years, 6 months ago by
- AuthorPosts
You must be logged in to reply to this topic.