我根本无法将javascript加载到wordpress中


I cannot load javascript into wordpress at all

好吧,我想这是我第四次问这个问题了。。。如果错误在我这边,我不会。还是怎样

好的,我只是想把这个测试弹出的javascript包含到我的wordpress插件文件中。。。

PLUGIN文件

<?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
*/
function popup_this() {
$src = plugins_url('/includes/test.js', __FILE__);
wp_register_script( 'links', $src );
wp_enqueue_script( 'links' );
wp_enqueue_script( 'jquery' );
}
add_action('init','popup_this');

测试文件在我的includes文件夹中。

test.js

<script type="text/javascript">
window.addEventListener('load',function(event){
   alert('hello there this is a test popup');
},false);
</script>

当我通过将test.js保存为html来测试弹出窗口时,弹出窗口运行良好,不会出错。

但是,当我把它包括在上面显示什么都没有发生在wordpress网站。

为了清楚起见,当我查看页面源代码时,文件路径是正确的。

再次感谢。。我希望这一次对我有用。

<script type="text/javascript">
window.addEventListener('load',function(event){
   alert('hello there this is a test popup');
},false);
</script>

js文件中不能有那些围绕代码的scritpt标记正如@Relic在评论中指出的那样,我错过了…