Javascript WP插件中的JQuery/PHP
我正在尝试在WP插件中运行这个JQueryJavascript WP插件中的JQuery/PHP,javascript,php,jquery,wordpress,Javascript,Php,Jquery,Wordpress,我正在尝试在WP插件中运行这个JQuery <?php function process_post(){ wp_enqueue_script('namespaceformyscript', 'http://code.jquery.com/jquery-1.9.1.min.js', array('jquery')); ?> <script type="text/javascript" > jQuery(document).re
<?php
function process_post(){
wp_enqueue_script('namespaceformyscript', 'http://code.jquery.com/jquery-1.9.1.min.js', array('jquery'));
?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
alert('hello');
});
</script>
<?php
}
add_action('init', 'process_post');
?>
jQuery(文档).ready(函数($){
警惕(“你好”);
});
此警报不会发生
我做错了什么?至于调用jQuery,这应该足够了: wp_排队_脚本('jquery') 这确保了即使多个插件将调用jquery(它们很可能会调用),它也不会被多次加载 其次,你没有使用正确的钩子。从关于init hook的文档中:
Runs after WordPress has finished loading but before any headers are sent.
()
作为一个完整的解决方案,请尝试以下方法(未经测试,但应该可以):
<?php
load_scripts() {
wp_enqueue_script('jquery');
wp_enqueue_script('yourcustomjavascript.js',
WP_PLUGIN_URL.'/yourpluginfolder/yourcustomjavascript.js',
array('jquery'));
}