Reputation: 6622
I am pretty new to Wordpress. I have a plugin that I created and is working fine, except that when I try to do a simple jQuery ready function inside an included javascript file it is not seeing jQuery and I am getting an undefined error. I am doing this before I include the HTML file content.
Here is the code I am using to load the script (which is loading the js file just fine)
add_action('admin_init', 'admin_references_scripts');
function admin_references_scripts() {
//Add CSS Files
wp_enqueue_style('admin-references-style', plugins_url('/css/admin-references.css', __FILE__ ));
wp_enqueue_style('admin-references-craftmap', get_stylesheet_directory_uri().'/css/craftmap.css');
//Add JS files
wp_register_script('admin-references-js', plugins_url('/js/admin-references.js', __FILE__ ), array('jquery', 'jquery-ui-core', 'jquery-ui-draggable'));
wp_enqueue_script('admin-references-js');
//Add the panel to the post type
add_meta_box('admin-references-control', 'Admin References', 'admin_references_meta', 'admin_references', 'advanced', 'high');
}
And the admin-references.js file looks simply like this
$(function() {
alert('here');
});
Here are my questions/problems
Upvotes: 0
Views: 284
Reputation: 166
/wp-admin/load-scripts.php
is a wp-admin call, not a front-end one.
Are you trying to do your jQuery in wp-admin or in the front (theme) ?
Have you checked you're running jQuery in no conflict mode..
aka, it should be:
jQuery(function() {
alert('here');
});
Upvotes: 1