0

I have two pages, events.php from plugin1 index.php from plugin2. in events.php. I am including jquery for ajax loading

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

<a onclick="show_trend(<?php echo $event->output('#_EVENTID');?>)" >Trend</a>

This ajax load works fine. From this ajax call, I am calling a function and rendering a div in index.php. What I am doing is creating a highchart. For this I am including

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>

in index.php function.

But I am not able to create charts beacuse jquery is not loading. In console, I am getting the following error

TypeError: $(...).highcharts is not a function

404. That’s an error.

The requested URL

/ajax/libs/jquery/1.8.2/jquery.min.js%20line%202%20%3E%20eval was not found on this server. That’s all we know.

Any suggestions?.

Edit

As suggested by TBI Infotech i have done the following thing in my function

function em_bookings_events_table() {
........
.......
.......
wp_enqueue_script('jquery');


}
 add_action( 'wp_enqueue_scripts', 'em_bookings_events_table' );

but now jquery is not loading.

1
  • Why do you need to load the external jquery library from google? I don't think there is any compatibility issues for which you need to load older versions of jquery. Jul 4, 2014 at 7:31

2 Answers 2

1

The proper way to include jquery in your plugin is

/**
 * Proper way to enqueue scripts and styles
 */
function theme_name_scripts() {
    wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}

add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
3
  • can uplease expalin. i have a function like function abc(){} . inside this function i want to include jquery from cdn.. can u edit ur answer as per this? Jul 4, 2014 at 4:52
  • The above answer also has the same thing it has a function theme_name_Script() in which jquery script have been called. Jul 4, 2014 at 5:04
  • pls See my updated question. Jul 4, 2014 at 5:14
1

Ok the problem i found in your above code is you have not mentioned the path of your library

function em_bookings_events_table() {
........
.......
.......
wp_enqueue_script('name_of_script','place Path_of_your_jquery_file here');


}
 add_action( 'wp_enqueue_scripts', 'em_bookings_events_table' );
5
  • Please don't post multiple answers, if you need to add/remove/modify anything in your original answer, do it in the form of an edit. :-) Jul 4, 2014 at 5:36
  • 2
    Not necessary.. Using wp_enqueue_script('jquery'); will load and enqueue the bundled jQuery from core. Here is the list of handles of the script already registered by core. codex.wordpress.org/Function_Reference/…
    – Abhik
    Jul 4, 2014 at 5:37
  • @Abhik then, can you tell me what is the issue Jul 4, 2014 at 5:57
  • @NishamMahsin Your code looks just fine. May be you should remove any other codes adding jquery. Also, do a hard refresh on your browser.
    – Abhik
    Jul 4, 2014 at 6:01
  • @Abhik i have some other html contents also there in function. is that any problem? Jul 4, 2014 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.