OK, this is driving me nuts:
I'm trying to build a simple Wordpress plugin, and I'm trying to make sure the js is separate from the php. I've gone through the codex, and various tutorials, but either they are all making assumptions, or I'm just an idiot because it's not working...Basically, I'm ultiamtely hoping to add some rows using ajax to a custom table when I add a post, but first of all I've just got to get this Hello World working on a Add Post page...
Surely It's dead easy:
Here's the javascript in myplug/js/myplugin.js:
jQuery(document).ready(function(){
alert("dothis");
});
Here's the version that works in the plugin (but is bad):
function admin_load_js(){
echo '<script type="text/javascript" src="http://www.mysite.com/wp-content/plugins/myplugin/js/myplugin.js"></script>';
}
add_action('admin_head', 'admin_load_js');
This is marginally better, but doesn't work (jQuery not defined):
function admin_load_js(){
echo '<script type="text/javascript" src="http://www.mysite.com/wp-content/plugins/myplugin/js/myplugin.js"></script>';
}
add_action('admin_enqueue_scripts', 'admin_load_js');
And this is the way I think it should be done, but doesn't work at all just doesn't do anything:
function admin_load_js(){
wp_register_script( 'custom_js', plugins_url( '/js/myplugin.js', __FILE__ ) );
}
add_action('admin_enqueue_scripts', 'admin_load_js');
Can someone please give me a clue here?? Even Google isn't my friend at the moment. Maybe because it's late, I don't know...