• Resolved huaxing0345

    (@huaxing0345)


    May I just ask if the cursor could focus on the search after search page load(or search button just clicked) please? I have been looked around and almost all commercial website is like that.

    thank you in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hi,

    You can use following code snippet:

    add_action( 'wp_head', 'aws_wp_head_focus' );
    function aws_wp_head_focus() {
    
        if ( ! is_search() ) {
            return;
        }
    
        ?>
    
        <script>
            window.addEventListener('load', function() {
                if ( typeof jQuery !== 'undefined' ) {
                    jQuery('.aws-container .aws-search-field:visible').first().focus();
                }
            }, false);
        </script>
    
    <?php }

    You need to add it somewhere outside the plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets.

    Regards

    Thread Starter huaxing0345

    (@huaxing0345)

    thank you so much for your response. unfortunately, the snippet does not work. nothing happened after I paste in my function.php.

    i also tried remove the space between ! and is_search(), still not work.

    we use Seamless integration with flatsome theme.

    thank you very much for your response anyway. thank you.

    Thread Starter huaxing0345

    (@huaxing0345)

    I find out from the console that the Flatsome theme search button originally set data-focus=”input.search-field” even I am using aws seamless integration.

    I tweaked the Flatsome theme search button changing it to data-focus=”input.aws-search-field”. and its achieved goal. I think your code may work but it’s the Flatsome theme problem.

    thank you very much again for your help. thank you.

    • This reply was modified 1 year, 6 months ago by huaxing0345.
    • This reply was modified 1 year, 6 months ago by huaxing0345.
    • This reply was modified 1 year, 6 months ago by huaxing0345.
    • This reply was modified 1 year, 6 months ago by huaxing0345.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘May I ask if the cursor could’ is closed to new replies.