javascript文件调用返回奇怪的路径
Wordpress javascript file call returns strange path
我正在尝试使用推荐的方法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
相关文章:
- 如何在d3.js中返回路径的y坐标
- 请求准备一个文件并返回路径,允许用户在准备好时下载
- 无法在ajax调用中发布绝对文件路径-无论我做什么,它都会返回斜杠
- 什么'这是返回元素的好方法's路径
- AWS S3 JavaScript 开发工具包 getSignedUrl 仅返回基本路径
- php文件上传返回文件和文件路径的有效性
- Native Phonegap、下载并创建文件、动态命名文件和返回路径
- 给定一个对象数组,创建一个函数,该函数返回一个 Object,该 Object 具有按类型分组的路径数组
- 返回路径中的最后一个目录
- 并非所有代码路径都返回值 (JavaScript)
- PhoneGap安卓应用程序需要获取外部SD卡路径,但它只返回内部SD卡路径
- 相对图像源路径使用 jQuery 返回 null
- 如何在 Gulp useref 中返回原始路径
- 节点Webkit-尝试从Webkit目录输入枚举目录下的文件,但只返回目录路径
- 链轮'asset_path不会返回生产中HTML资产的摘要路径
- 将路径传递给php将返回未定义的结果
- 返回带有路径JSON的项目描述
- 使用nodejs路径模块返回目录
- jQuery.val()根据选择器路径返回不同的值
- 对于非异步路径返回什么