Ronny K
Ronny K

Reputation: 3731

I cannot load javascript into wordpress at all

Ok I am asking this question I think for the 4th time... I don't if the error is on my side. or what.

Ok I am just trying to include this test popup javascript into my wordpress plugin file...

PLUGIN file

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

the test file is in my includes folder.

test.js

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

</script>

When I test the popup by saving the test.js as a html, the popup works fine prooving no error.

But when I include it as shown above nothing happens in the wordpress site.

for clarity the file path is correct as I can tell when I view the page source.

thanks again.. I hope this time it works for me.

Upvotes: 0

Views: 230

Answers (1)

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

</script>

you cannot have those scritpt tags surrounding your code in a js file as fellow @Relic pointed out in the comments, i missed it...

Upvotes: 1

Related Questions