it's like a small headache now, I am trying to enqueue the javascript files in functions.php but they are not working after 100's of tries. Let me know what is the issue, why my javascript file isn't working.
<?php
function ct_styles(){
wp_enqueue_style('style', get_stylesheet_uri());
wp_enqueue_style('style_bootstrap', get_theme_file_uri('assets/css/vendor/2-bootstrap.min.css'));
wp_enqueue_style('style_pack', get_theme_file_uri('//unpkg.com/aos@next/dist/aos.css'));
}
add_action('wp_enqueue_scripts', 'ct_styles');
function ct_scripts(){
wp_enqueue_script('jquery');
wp_enqueue_script( 'ct_bootstrap', get_theme_file_uri( '/assets/js/vendor/2-bootstrap.min.js' ), array(), '1.0.0', true );
wp_enqueue_script( 'simplebar', get_theme_file_uri( '/assets/js/vendor/4-simplebar.min.js' ), array(), '1.0.0', true );
wp_enqueue_script( 'ct_pack', get_theme_file_uri( '//unpkg.com/aos@next/dist/aos.js' ), array(), '1.0.0', true );
wp_enqueue_script( 'ct_lazy', get_theme_file_uri( '/assets/js/vendor/lazysizes.min.js' ), array(), '1.0.0', true );
wp_enqueue_script( 'ct_main', get_theme_file_uri( '/assets/js/scripts.min.js' ), array(), '1.0.0', true );
}
add_action('wp_enqueue_scripts', 'ct_scripts');
?>
Try like this
get_template_directory_uri()
= parent theme get_stylesheet_directory_uri()
= child theme
function add_theme_scripts() {
wp_enqueue_style( 'style_bootstrap', get_template_directory_uri(). '/assets/css/vendor/2-bootstrap.min.css', array(), null, 'all');
//Add other required css
wp_enqueue_script( 'ct_bootstrap', get_template_directory_uri() .'/assets/js/vendor/2-bootstrap.min.js',array ( 'jquery' ), null, true);
//Add other required js
}
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.