I have tried to include my javascript file in the following way:

function theme_scripts()
{

    wp_enqueue_scripts( 'custom-script', get_template_directory_uri() . '/js/menu-fix.js',array('jQuery'), true);
}

add_action('init', 'theme_scripts');

This file is included in functions.php

But for some reason the script does not get included.

I have got wp_head() in header.php and wp_footer() in footer.php.

Edit

So I changed my script to:

    function theme_scripts()
    {
    wp_enqueue_scripts( 'custom-script', get_template_directory_uri() . '/js/menu-fix.js',array('jquery'), '1.0',true);
    }
add_action('wp_enqueue_scripts', 'theme_scripts');

But still it isn’t loaded.

This is how my footer.php looks like:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
   <script src="<?php bloginfo('template_url'); ?>/js/bootstrap.min.js"></script>
   <?php wp_footer();?>

3 Answers
3

You’re mixing up the singular wp_enqueue_script, which adds a script, with the plural wp_enqueue_scripts which is an action and a function that triggers that action. I think you want

function theme_scripts()
{
    wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/js/menu-fix.js', array('jquery'), '1.0', true);
}
add_action('wp_enqueue_scripts', 'theme_scripts');

i.e. register against the enqueue_scripts-plural action that calls enqueue_script-singular.

Leave a Reply

Your email address will not be published. Required fields are marked *