WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Can't link to Javascript files (5 posts)

  1. garethn
    Member
    Posted 3 years ago #

    Hi,

    I am running an offline theme in WAMP on Windows 7, and have installed in C:\ rather than Program Files to avoid security issues/annoyances.

    I have used wp_enqueue_scripts twice, firstly for jquery and then jcarousellite. The problem is, the browser can't 'see' jcarousellite. When I click on the link in the HTML file, it throws up a 500 Internal Server Error. This does not happen for jquery, which is linked through wp-include rather than wp-content.

    In header.php this is written thus:

    wp_enqueue_script("jquery");
    wp_enqueue_script("jcarousel",get_bloginfo('template_directory')."/scripts/jcarousellite.js",array('jquery'));

    This comes through as:

    <script type='text/javascript' src='http://localhost/sbl/wp-includes/js/jquery/jquery.js?ver=1.4.4'></script>
    <script type='text/javascript' src='http://localhost/sbl/wp-content/themes/sbl3/scripts/jcarousellite.js?ver=3.1.3'></script>

    Is WordPress causing this or WAMP? I'd be most grateful of any help as I've tried everything I can think of!

    Gareth

  2. mattyrob
    Member
    Posted 3 years ago #

    @Gareth,

    wp_enqueue_scripts is trying to queue the script for you using the path details given.

    Is the path as listed above correct? In other words, is that where the js file is actually located? If it isn't there then your code is pointing both WordPress and WAMP to the wrong location. This will almost certainly throw some sort of error.

  3. garethn
    Member
    Posted 3 years ago #

    Thanks.

    The files are, respectively, in these locations:

    C:\wamp\www\sbl\wp-includes\js\jquery\jquery.js
    C:\wamp\www\sbl\wp-content\themes\sbl3\scripts\jcarousellite.js

    Surely if the first one works then so should the second!?

    Could WAMP, Windows or WordPress prevent access to the latter file like can happen on a server if your permissions are wrong?

  4. mattyrob
    Member
    Posted 3 years ago #

    @Gareth,

    Try to think less in terms of the Windows directory structure (i.e. starting C: etc).

    If you are running WAMP, in your browser I suspect you can directly access:
    http://localhost/sbl/wp-includes/js/jquery/jquery.js

    Can you also directly access:
    http://localhost/sbl/wp-content/themes/sbl3/scripts/jcarousellite.js

    I would guess not. This is either because the file is not at that location (but it looks as though it actually is) or (more likely now) there is a permissions error on the folder meaning that WAMP is denied access to that resource. Check the permissions and make sure WAMP can access the appropriate folders that contain your code.

  5. garethn
    Member
    Posted 3 years ago #

    Ok, I moved the file to the template folder and it worked so it was definitely a permission issue.

    I've created a new folder called /js/ and put it in there and it seems to work. I can't see a difference in permissions between them, but it works. Must be something I can't see or a reserved word kind of problem.

    Either way, thanks for your help!

    Gareth

Topic Closed

This topic has been closed to new replies.

About this Topic