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'); ?>
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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_styleshooks 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 thewp_print_styleshook to enqueue styles — your styles may end up in the admin.
The fix: Usewp_enqueue_scriptsinstead. 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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0