javascript文件调用返回奇怪的路径

Wordpress javascript file call returns strange path

本文关键字:路径 返回 文件 调用 javascript      更新时间:2023-09-26

我正在尝试使用推荐的方法wp_enqueue_script在Wordpress子主题中包含jQuery和我的自定义脚本文件

<?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 

谢谢。

试试这个plugins_url( 'js/customScripts.js', __FILE__ )代替plugins_url( '/js/customScripts.js', __FILE__ )(去掉第一个斜杠)

看:http://codex.wordpress.org/Function_Reference/plugins_url