有人可以告诉我如何将此JavaScript文件包含到我的WordPress插件中。我尝试了所有的wp_enqeue_script()方法,但没有任何反应。如何在WordPress插件中加载Javascript
好的,这里是我的示例插件代码,带有解释我想要的注释。
<?php
/*
Plugin Name: Ava Test
Plugin URI: http://#.com
Description: A plugin that is used for my javascript tests
Author: Ronny Kibet
Author URI: http://ronnykibet.com
version: 1.001
*/
include(popup.js);
/*when I include it this way, it works fine, but gives an error when I activate the plugin
'plugin generated 453 characters ...'
*/
function popup() {
$src = plugins_url('popup.js', __FILE__);
wp_register_script('popup', $src);
wp_enqueue_script('popup');
}
/*
when I included it this way, plugin is activated but nothing happens.
*/
?>
这是popup.js
<script type="text/javascript">
function popup(){
alert('hello there this is a test popup')
}
</script>
<body onload="popup()">
</body>
所以没有任何人知道如何调用这个脚本在WordPress插件正常工作?
我试过这一个, – 2012-02-04 18:47:50
你应该把你的js文件命名为ava_test_.js,并把它放在你的插件目录下的一个名为js的文件夹中,你是否这样做? – aghoshx 2012-02-07 14:56:04
正确的是'add_action('wp_enqueue_scripts',' ava_test_init');' – brasofilo 2014-09-16 19:58:03