My jquery file is not working in WordPress.
The error is here:
My js code:
(function($) { $(document).ready(function(){ $('#read_more').click(function() { $('.display_none').show().animate({'transition': '2s'}); }); }); })( jQuery );
I have an added custom-script.js
file in functions.php
like this:
function aristo_css_js(){ wp_enqueue_script('myjs', get_template_directory_uri().'/assets/js/custom-script.js'); wp_enqueue_script('myjs'); } add_action('wp_enqueue_scripts','aristo_css_js');
What is the main problem for this was not working? But if I added custom script code before body
tag it’s working. ?
Advertisement
Answer
I solve my own question by add jquery
file before my custom-script
wp_enqueue_script('jquery-main', get_template_directory_uri().'/assets/js/jquery-3.3.1.min.js'); wp_enqueue_script('myjs', get_template_directory_uri().'/assets/js/custom-script.js');