I have this jquery code inside my wordpress admin page that checks if the input value is empty.


     var link = $j('#input').val();
    if(link == ''){
         alert('hi there');



Now if the form is empty it will alert ' hi there'.

the plugin works fine but the alert does not show on the main page. Only in the admin section.

what would be the problem?

here is how I am calling jquery.

function test(){
wp_enqueue_script('myscript', plugin_dir_url(__FILE__). 'js/test.js');


I would like that if the value of input is empty, the alert show also in the wordpress homepage and not only in the admin page.

  • The first bit of javascript is where exactly? In your test.js file?
    – Wyck
    Commented Jun 21, 2012 at 16:05
  • yes Wyck thats test.js
    – Ronny K
    Commented Jun 21, 2012 at 16:33

2 Answers 2

function test(){
    wp_enqueue_script('myscript', plugin_dir_url(__FILE__). 'js/test.js',array('jquery'));
  • added that, but same thing Gembel. the alert only shows at the admin page.
    – Ronny K
    Commented Jun 21, 2012 at 16:39
  • hmm.. not sure why. is your js appear when you view page source? just in case you forget to add wp_head(); in your template :D
    – Dazilio
    Commented Jun 21, 2012 at 16:48
  • yes it does appear Gembel.
    – Ronny K
    Commented Jun 21, 2012 at 16:57
  • how about testing your js in jsbin? here is my test jsbin.com/omumit/edit#javascript,html
    – Dazilio
    Commented Jun 21, 2012 at 17:54

I believe the problem is that you are enquequeing jquery.

You don't need to do that, as WordPress does it by default. Just remove


and everything should be fine.

  • that will never work. this is a plugin and I am calling jquery.
    – Ronny K
    Commented Jun 21, 2012 at 16:32
  • But you do not need to call jQuery! Trust me, I have recently submited plugin to WordPress.org and before approving it, I needed to remove jQuery call. There is no need for calling jQuery with plugins! Commented Jun 21, 2012 at 16:35
  • ok well... gave that a shot too.. no changes.
    – Ronny K
    Commented Jun 21, 2012 at 16:40
  • What does your browser console say? Commented Jun 21, 2012 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.