2012-02-07 61 views
0

好吧我問這個問題,我想第四次...我不知道如果錯誤是在我身邊。或者是什麼。我無法加載javascript到wordpress的所有

好吧,我只是想包括這個測試彈出javascript改成我的WordPress插件文件...

插件文件

<?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'); 

測試文件是在我的文件夾包含。

test.js

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

</script> 

當我通過保存test.js爲HTML測試彈出,彈出的工作正常prooving沒有錯誤。

但是,當我如上所示包含它時,wordpress站點沒有任何反應。

爲了清楚起見,文件路徑是正確的,因爲我可以告訴我什麼時候查看頁面源代碼。

再次感謝..我希望這次它適合我。

+1

得到,當你保存它擺脫了腳本標籤作爲JS,這是在導入時處理的。 – Relic 2012-02-07 17:05:33

+1

做到了這一點,並在閃光燈工作。謝謝Relic ...哇! – 2012-02-07 17:09:10

+1

有時候它是最愚蠢的東西= D – Relic 2012-02-07 17:17:13

回答

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

</script> 

你不能有圍繞一個js文件 代碼老鄉@Relic在評論中指出的那些scritpt標籤,我錯過了......

+0

-1爲了解答我的評論。 – Relic 2012-02-07 17:20:29

+0

謝謝:)我沒有看到你的評論,但爲什麼你沒有回答呢? – 2012-02-07 17:33:00

+0

@Relic Andre是對的。你應該已經發布了答案 – 2012-02-07 17:35:44