Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using wp_enqeue_script to link to a custom.js file in my plugins folder. However I am expecting a link to show up on the page but it doesn't is there something else I am supposed to other than place this in the header.

<?php wp_enqueue_script('myscript', '/wp-content/plugins/myplugin/myscript.js'); ?>
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

When and where to load styles & scripts 1) & 2)

» If you are enqueueing scripts and styles, you will want to use one of these three hooks: «

  • wp_enqueue_scripts (for the frontend)
  • login_enqueue_scripts (for the login screen)
  • admin_enqueue_scripts (for the admin dashboard)

» Don’t let the names fool you — they are for both scripts and styles. We’ll probably add equivalent *_enqueue_styles hooks in 3.4 just to make it more obvious, but these hooks have all existed for some time now. A possible incompatibility with WordPress 3.3 could arise if you are using the wp_print_styles hook to enqueue styles — your styles may end up in the admin. The fix: Use wp_enqueue_scripts instead. Yes, it’s that easy. Edit: Yes, the same goes for registering styles. Registering or enqueueing (styles or scripts) should occur on *_enqueue_scripts. «

Pathes should stay relative 3)

Keep in mind that there're

  • Plugins
  • MU-Plugins
  • Drop-Ins
  • Themes
  • Themes in directories registered via register_theme_directory( $dir );

Debugging

1st check if the <script> is present in your pages source code.

   ✓ → The file was hooked

   × → The hook is wrong (mostly too late)

2nd check if a file is missing with your Chrome Dev Bar or FF Firebug.

   ✓ → The file was found

   × → The path or filename is wrong (mostly typo or wrong path function)

3rd try to call the file from it's path manually to determine if you have no typo.

   ✓ → The file was found

   × → The path or filename is wrong (mostly typo or wrong path function)

Notes about sources:

1. Above is a quote Quote from WP Devel about where to add calls to wp_enqueue/register_script/style():

2. Look at the related codex page to read the same about the hooks to use

3. Another answer here on WPSE about pathes, that sums up whatcan be read in codex

share|improve this answer
    
so if I am doing it correctly, I still don't understand why I can't see the script in the outputted source. –  Anders Kitson Feb 21 '12 at 1:50
    
Look into your dev bar or firebug and check the resources if the file is missing. See Update (img). –  kaiser Feb 21 '12 at 1:52
    
the file is missing in the resource tab. I don't understand why though. And i still don't understand why this doesn't output at a <script tag> to the html how else is the browser getting the js –  Anders Kitson Feb 21 '12 at 1:55
    
Re-read the advice: Try to add the path manually and see if the file loads. If it doesn't, then you have a typo with the filename. –  kaiser Feb 21 '12 at 1:58
    
And if you can load it, then you need to update your Q with what exactly you tried plus your whole surroundings: How do you load the script, on which hook, etc. Just try to imagine, what info could would be needed to help you. Two sidenotes: Your path is simply wrong. Read the linked answer on how to set the correct path. Second: What's "connected"? Your Q-title sounds missleading. –  kaiser Feb 21 '12 at 2:00
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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