0

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.

4
  • 1
    get rid of the script tags when you save it as a JS, that's handled on import. Commented Feb 7, 2012 at 17:05
  • 1
    did that and in flash it worked. thanks Relic... WOW!!! Commented Feb 7, 2012 at 17:09
  • 1
    Sometimes it's the silliest of things =D Commented Feb 7, 2012 at 17:17
  • thanks again relic... now that brings me to another question.. how do I know which tags to remove? I mean I was using that as a test and the main file has a lot of <script> tags on it... some even in the center.. thanks Commented Feb 7, 2012 at 17:23

1 Answer 1

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...

Sign up to request clarification or add additional context in comments.

3 Comments

thank you :) i hadn't seen your comment, but why didn't you answer then?
@Andre If you didn't see it, then that's fine, but Relic's comment was first on the list and predates this answer by 18 minutes, so it's hard to miss. At the very least you should add a citation to Relic as a gesture... he may not have added it in as an answer, but for these super simple questions answering in comments is pretty common.
Yeh,true... tried to undo my -1, you have to edit your answer for me to do that though.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.