WordPress.org

Ready to get started?Download WordPress

Forums

Get my Javascript On! (3 posts)

  1. cicakchanson
    Member
    Posted 1 year ago #

    Hello, I am new to javascript so I'm sure this question is going to be a snap so thanks for your help. I'm trying to call up a javascript file that I've created in order to get an accordion menu on my site working. I have successfully gotten it to work by placing the following code in the "header."

    <script src="<?php bloginfo( 'template_directory' ); ?>/javascripts/jquery.js" language="javascript" type="text/javascript"></script>
       <script src="<?php bloginfo( 'template_directory' ); ?>/javascripts/scripts.js" language="javascript" type="text/javascript"></script>

    Now I do know that this is not the right way to call up scripts since it can result in jquery conflicts so I'd really like to use the wp_enqueue_script method. So far I've come up with the following code

    <?php
    wp_register_script(
        'scripts',
        '/javascripts/scripts.js',
        array('jquery'),
        false,
        false
    );
    wp_enqueue_script('scripts');
    
    ?>

    So the issue with the code I've written is that I get an error with Chrome's inspector that says "GET http://www.thewanderingguru.com/m2world/javascripts/scripts.js?ver=1 404 (Not Found)"

    I'm unsure what to make of this since there isn't a "version" of this file. I created it from code I got on the net HERE

    Thanks for any help you can offer

  2. varkeychaya
    Member
    Posted 1 year ago #

    in the code above you have mentioned the php function bloginfo( 'template_directory' ) but not while using the enqueue below

  3. cicakchanson
    Member
    Posted 1 year ago #

    Thanks for the help. Admittedly I'm very new at PHP and Javascript. I have found other sites that explain how to do this but I still can't quite get it to work. How would I call the template directory in the enqueue? Thanks for the help.

Topic Closed

This topic has been closed to new replies.

About this Topic