1

I am trying to enqueue a script in my WordPress function.php I cant seem to get it to pick up the script.

works in this format if include in header

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

however when i include in functions.php it dose not work

wp_enqueue_script('bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js', array(), '3.3.6', true);

can anyone see why it will not work when I enqueue it ?

FULL CODE

function theme_js()
{
    wp_enqueue_script('jquery-js', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array(), '3.1.1', true);
    wp_enqueue_script('bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js', array(), '3.3.6', true);
    wp_enqueue_script('html5shiv-js', 'https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js', array('jquery'), '3.7.2', true);
    wp_enqueue_script('respond-js', 'https://oss.maxcdn.com/respond/1.4.2/respond.min.js', array('jquery'), '1.4.2', true);
    wp_enqueue_script('custom', get_template_directory_uri() . '/js/custom.js', array(), null, true);
}

add_action('wp_enqueue_scripts', 'theme_js');

1 Answer 1

1

You are loading it in the footer, which may not be what you mean to do. You have the final flag set to true.

For reference:

wp_enqueue_script( string $handle, string $src = '', array $deps = array(), string|bool|null $ver = false, bool $in_footer = false )

Try (now includes the de-register for the jQuery you are queuing):

FULL CODE

if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
 function my_jquery_enqueue() {
      wp_deregister_script('jquery');
      wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js", false, null);
      wp_enqueue_script('jquery');
}

function theme_js(){
    // wp_enqueue_script('jquery-js', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('jquery'), '3.1.1', true);
    wp_enqueue_script('bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js', array('jquery'), '3.3.6', true);
    wp_enqueue_script('html5shiv-js', 'https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js', array('jquery'), '3.7.2', true);
    wp_enqueue_script('respond-js', 'https://oss.maxcdn.com/respond/1.4.2/respond.min.js', array('jquery'), '1.4.2', true);
    wp_enqueue_script('custom', get_template_directory_uri() . '/js/custom.js', array('jquery'), null, true);
}

add_action('wp_enqueue_scripts', 'theme_js');

Additionally check: Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3 at bootstrap.min.js?ver=3.3.6:6 at bootstrap.min.js?ver=3.3.6:6 ;)

Sign up to request clarification or add additional context in comments.

13 Comments

Unfortunately this dose not work still, thanks anyways
Can you post the entire section of code from your functions file please
I trust its actually wrapped in an initialised function?
I added this to the code above. So it now de-registers the jquery, then enqueue it
Thanks mate, appreciate it. I cannot imagine why it is not working now. Anything in console?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.