我在排队脚本时遇到了麻烦。我不确定它为什么不起作用。我知道脚本代码本身的作品。WordPress的:我如何正确排入此JavaScript文件?
另一个问题 - 如果我试图包含这个.js文件,js代码本身是否应该被<script></script>
包围?
编辑 - **我忘了提及我正在制作一个扩展到一个现有的插件。我想编写排队代码在我的扩展的functions.php文件中。我该怎么做呢?以下是我的设置。 **注意这是给我的错误:Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'Find_Do_For_Anspress' does not have a method 'fd_enqueue_front' in C:\wamp\www\wordpress\wp-includes\plugin.php on line 503
我的设置
anspress个问题,answer.php
require_once __DIR__ . '/../find-do-for-anspress/find-do-for-anspress.php'; //I left out most of the other code but this correctly includes the file below
发现-DO换anspress。 php
public function includes() {
require_once(FIND_DO_FOR_ANSPRESS_DIR.'/functions.php'); // Again, I'm keeping it short and simple
}
的functions.php
add_action('wp_enqueue_scripts', array($this, 'fd_enqueue_front'));
function fd_enqueue_front()
{
wp_enqueue_script('braintree-js', plugin_dir_url('braintree-js.js') . 'braintree-js.js', array());
}
布伦特里-js.js
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
var clientToken = "12345";
braintree.setup(clientToken, "dropin", {
container: "payment-form"
});
</script>
为什么你还没有尝试使用'plugins_url()'来获取'find-do-for-anspress'插件的url? –
plugins_url(__FILE__)为您带来当前插件文件,然后您可以轻松排入js。 –
http://wordpress.stackexchange.com/questions/99067/enqueue-scripts-inside-a-class-in-a-plugin这个链接将帮助你获得。 –