Site logo

[Resolved] Code written in function.php not working globally…

Home Forums Support [Resolved] Code written in function.php not working globally…

Home Forums Support Code written in function.php not working globally…

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #2456684
    iamarghya

    I have written an AJAX call for my search result to suggest posts from my website as they type. I wrote the code in child-theme, and the code is running in that browser, Then when I am trying to run it on a different browser or in incognito mode it won’t run. In the console it is showing jQuery is not Defined.

    #2456691
    iamarghya

    I have added jQuery to my site as Tom said in a post but it is not the latest version I think and it is showing JQMIGRATE: Migrate is installed, version 3.3.2, is this ok?

    #2456695
    iamarghya

    WordPress does include jQuery so why did I need to add the script to add the jQuery, any answer?

    #2456851
    David
    Staff
    Customer Support

    Hi there,

    Yes, WordPress does include jQuery, but it needs to be enqueued by a theme, plugin or function.
    GP doesn’t use jQuery, unless you use the Sticky Navigation option, and therefore doesn’t enqueue the script.
    So you will need to šŸ™‚

    #2456919
    iamarghya

    I have added this code to enable it, is it ok? And in the browser console, it is showing JQMIGRATE: Migrate is installed, version 3.3.2… is it also ok?

    add_action( 'wp_enqueue_scripts', function() {
        wp_enqueue_script( 'jquery' );
    } );
    #2456948
    David
    Staff
    Customer Support

    You can do this and it will only load the core jQuery and not the jqmigrate which you shouldn’t require.

    
    add_action( 'wp_enqueue_scripts', function() {
        wp_enqueue_script( 'jquery-core' );
    } );
    #2456982
    iamarghya

    Yes, now that MIGRATE message is also gone and it is working. As I said I did this AJAX search on the search form page but I have added a normal search bar on the homepage can I also have the same results with it? I have added the page link where it is working, but you have to clear that search phrase and give input, and it will suggest you post based on what you type…Now if you go to the homepage I want to do the same search process, can you give me an idea, of how to do it?

    #2457675
    David
    Staff
    Customer Support

    How did you add it to the Search page ? I assume HTML ?

    If yes, use a HTML block to add it to your homepage.

    #2458423
    iamarghya

    Oh ok then I need to use a fresh one, okay. Thanks a lot ā¤

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.