Site logo

Archived topic

Code written in function.php not working globally...

8 replies · Started by iamarghya on December 9, 2022

Viewing posts 1–9 of 9

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.

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?

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

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 :)

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' );
} );

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' );
} );

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?

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

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

Oh ok then I need to use a fresh one, okay. Thanks a lot ❤

This archived topic is closed to new replies.