• Resolved Fi Fi P

    (@fi-fi-p)


    I have been looking through a lot of documentation for this and really need a good clear tutorial if one exists. I have made the move from Dreamweaver to WordPress and would like to implement some javascript actions.
    From a previous topic I have followed I have created a folder ‘js’ in my child them area and in this I have a tutorial.js file with my JQuery code.
    The code below has then been inserted within my home-page.php file just before the div I want to add an action to:

    <!–CALL CUSTOM JS –>

    <script type=”text/javascript” src=”../wp-includes/js/jquery/jquery.js”></script>
    <script type=”text/javascript” src=”../js/jquery.validate.min.js”></script>
    <script type=”text/javascript” src=”../js/tutorial.js”></script>

    I have then added a ‘j’ after each use of $ within my JQuery file.

    It doesn’t work. Any ideas on how I can do this?! There is a lot of threads about this but none are very clear as to what is to go where!
    Any help would be really appreciated! xx

Viewing 5 replies - 1 through 5 (of 5 total)
  • You need to correctly enqueue your .js files. Try reviewing wp_enqueue_script().

    Thread Starter Fi Fi P

    (@fi-fi-p)

    Thanks for your response but I don’t understand. Do I need to add that code: wp_enqueue_script() somewhere? It is to go in functions.php?

    Do I need to add that code: wp_enqueue_script() somewhere?

    Yes

    It is to go in functions.php?

    Yes

    Thread Starter Fi Fi P

    (@fi-fi-p)

    I added:

    function my_scripts_method() {
    wp_enqueue_script(
    ‘custom-script’,
    get_stylesheet_directory_uri() . ‘/js/tutorial.js’,
    array( ‘jquery’ )
    );
    }

    but no change

    You just need to enqueue the function now. Try:

    function my_scripts_method() {
    	wp_enqueue_script(
    	'custom-script',
    	get_stylesheet_directory_uri() . '/js/tutorial.js',
    	array( 'jquery' )
    	);
    }
    add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘JQuery Trouble’ is closed to new replies.