我正在尝试使用推荐的方法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' );
?>
这样可以正常工作,包括jQuery,但它为我的自定义脚本吐出了这条路径。
http://localhost:15869/wp-content/plugins/C:/Users/Kyle/Documents/MyWebSites/TomWictor.com/wp-content/themes/twentywelve-child/js/customScripts.js?ver=3.5
这显然是错误的。我不认为它与在本地主机上开发(使用Microsoft WebMatrix 2)有什么关系,但更多的是与Wordpress解密路径的方式有关?我不确定..
我怎样才能让它吐出正确的道路?
twentywelve-child/js/customScripts.js
感谢。
答案 0 :(得分:1)
试试这个plugins_url( 'js/customScripts.js', __FILE__ )
而不是plugins_url( '/js/customScripts.js', __FILE__ )
(删除你的第一个斜杠)