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
wp_enqueue(...);
(line 13 in your functions.php file) isn't a valid function name. It's (in this case) wp_enqueue_script() :P – cabrerahectorwp_register_style()
to register a JS file. That's whatwp_enqueue_script()
is for. – cabrerahector