0

Hi I am a beginner and creating simple wordpress template. Everything works except the code line in bold in my functions.php file (wp_enqueue('jquery');). When I exclude it the error goes away, but I don't see JQuery added by wordpress when I view sourcecode. Not sure if this is code issue or Jquery version issue. I tried adding JQuery migrate plugin and still same error. I am running all of this on local machine set up by Laragon. Below is my code and error. Appreciate any help.

Here is my functions.php file:

    <?php

function load_css(){
    wp_register_style('bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', array(), false, 'all');
    wp_enqueue_style('bootstrap');
}
add_action('wp_enqueue_scripts', 'load_css');


function load_js(){
     wp_enqueue('jquery');
     wp_register_style('bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', 'jquery', false, true);
     wp_enqueue_script('bootstrap');
 }
 add_action('wp_enqueue_scripts', 'load_js');

here is header.php file:

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
<?php wp_head();?>
</head>
<body>

here is footer.php file

<?php wp_footer();?>
</body>
</html>

here is front-page.php file

<?php get_header();?>
<?php get_footer();?>

error message: Fatal error: Uncaught Error: Call to undefined function wp_enqueue() in C:\laragon\www\test\wp-content\themes\SeanTheme\functions.php:13 Stack trace: #0 C:\laragon\www\test\wp-includes\class-wp-hook.php(287): load_js('') #1 C:\laragon\www\test\wp-includes\class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array) #2 C:\laragon\www\test\wp-includes\plugin.php(484): WP_Hook->do_action(Array) #3 C:\laragon\www\test\wp-includes\script-loader.php(2004): do_action('wp_enqueue_scri...') #4 C:\laragon\www\test\wp-includes\class-wp-hook.php(287): wp_enqueue_scripts('') #5 C:\laragon\www\test\wp-includes\class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array) #6 C:\laragon\www\test\wp-includes\plugin.php(484): WP_Hook->do_action(Array) #7 C:\laragon\www\test\wp-includes\general-template.php(3005): do_action('wp_head') #8 C:\laragon\www\test\wp-content\themes\SeanTheme\header.php(8): wp_head() #9 C:\laragon\www\test\wp-includes\template.php(730): require_once('C:\laragon\www\...') #10 C:\laragon\www\test\wp-includes\template in C:\laragon\www\test\wp-content\themes\SeanTheme\functions.php on line 13

2
  • As the error message states, wp_enqueue(...); (line 13 in your functions.php file) isn't a valid function name. It's (in this case) wp_enqueue_script() :P Commented Mar 3, 2021 at 22:49
  • Also, you shouldn't be using wp_register_style() to register a JS file. That's what wp_enqueue_script() is for. Commented Mar 3, 2021 at 22:52

1 Answer 1

1

WordPress automatically loads jQuery for you, if another script requires jquery simply specify it in the $deps parameter, when enqueuing your other JavaScript files. So remove wp_enqueue('jquery').

function load_js(){
     wp_enqueue_script('bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), null, true);
 }
 add_action('wp_enqueue_scripts', 'load_js');
Sign up to request clarification or add additional context in comments.

1 Comment

Thx much for the response and explanation @Phil

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.