wp_enqueue_script isn’t connecting my custom js file

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

Related posts

Leave a Reply

1 comment

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

       &check; → 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.

       &check; → 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.

       &check; → 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