Reputation: 67194
I'm trying to includ jQuery and my custom script file in a Wordpress Child theme using the recommended method wp_enqueue_script
<?php
function wptuts_scripts_with_jquery()
{
// Register the script like this for a plugin:
wp_register_script( 'customScripts', plugins_url( '/js/customScripts.js', __FILE__ ), array( 'jquery' ) );
// or
// Register the script like this for a theme:
wp_register_script( 'customScripts', get_template_directory_uri() . '/js/customScripts.js', array( 'jquery' ) );
// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script( 'customScripts' );
}
add_action( 'wp_enqueue_scripts', 'wptuts_scripts_with_jquery' );
?>
This works fine including jQuery, but it spits out this path for my custom script.
http://localhost:15869/wp-content/plugins/C:/Users/Kyle/Documents/MyWebSites/TomWictor.com/wp-content/themes/twentywelve-child/js/customScripts.js?ver=3.5
This is obviously wrong. I don't think it has anything to do with developing on a localhost (using Microsoft WebMatrix 2) but more to do with the way Wordpress deciphers paths? I am not sure..
How can I get it to spit out the proper path?
twentywelve-child/js/customScripts.js
Thanks.
Upvotes: 0
Views: 117
Reputation: 527
Try this plugins_url( 'js/customScripts.js', __FILE__ )
instead of plugins_url( '/js/customScripts.js', __FILE__ )
(remove your first slash)
Look: http://codex.wordpress.org/Function_Reference/plugins_url
Upvotes: 1