有人可以告訴我如何將此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