-
AuthorPosts
-
July 16, 2021 at 4:10 pm #1310412
Hello,
I remember that once, when you clicked on the search icon, the pointer was already in the text field. Now I have to click insideI see that in the Enfold demo autofocus is working correctly
How can restore it?
Thank you Mauro
July 18, 2021 at 11:30 pm #1310646Hey profumopuntoit,
Thank you for your patience and for the link to your site, I didn’t find why this is occurring but I was able to put together this script to correct the issue, I tested it on your site by injecting it via the browser so it should work for you once to add it to your child theme functions.phpfunction custom_focus_script() { ?> <script> function waitForElm(selector) { return new Promise(resolve => { if (document.querySelector(selector)) { return resolve(document.querySelector(selector)); } const observer = new MutationObserver(mutations => { if (document.querySelector(selector)) { resolve(document.querySelector(selector)); observer.disconnect(); } }); observer.observe(document.body, { childList: true, subtree: true }); }); } waitForElm('#s').then(elm => elm.focus()); </script> <?php } add_action('wp_footer', 'custom_focus_script');
Best regards,
MikeJuly 28, 2021 at 4:14 pm #1313062Thank you Mike,
it works
The only thing is that when I open funtions.php in Dreamweaver (CS6) it says that there is an error at the line
return new Promise(resolve => {
Please see https://www.loom.com/i/632444c3a9ab4df19904170915171a58
I have other closing php tag followed by a <script> but they do not raise errors
There is anything that I can do?
Thank you anyway
MauroJuly 29, 2021 at 10:53 am #1313204Hi,
Sorry I don’t use Dreamweaver, I use Visual Studio Code and I don’t get an error in it or in the WordPress theme editor.
Perhaps Dreamweaver is not recognizing this syntax correctly or there is a better way to write this that I don’t know about.Best regards,
MikeAugust 7, 2021 at 10:51 pm #1315063Ok thank you anyway Mike
August 7, 2021 at 11:56 pm #1315067Hi,
Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.Best regards,
Mike -
AuthorPosts
- The topic ‘Search autofocus’ is closed to new replies.