Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #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 inside

    I see that in the Enfold demo autofocus is working correctly

    How can restore it?

    Thank you Mauro

    #1310646

    Hey 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.php

    function 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,
    Mike

    #1313062

    Thank 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
    Mauro

    #1313204

    Hi,
    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,
    Mike

    #1315063

    Ok thank you anyway Mike

    #1315067

    Hi,
    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

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Search autofocus’ is closed to new replies.