【发布时间】:2012-02-26 20:27:01
【问题描述】:
谁能告诉我如何将此 javascript 文件包含到我的 wordpress 插件中。我已经尝试了所有 wp_enqeue_script() 方法,但没有任何反应。
好的,这是我的示例插件代码,其中 cmets 解释了我想要什么。
<?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 插件中正常工作吗?
【问题讨论】:
标签: php javascript wordpress