I'm developing a custom WordPress theme from scratch and now I faced a problem with loading css and js files. I have searched everywhere to see how can I be able to load those files and I did this on my functions.php
file:
<?php
function catalog(){
wp_enqueue_style('bootstrap', get_template_directory_uri() . 'css/bootstrap.min.css');
wp_enqueue_style('style', get_stylesheet_uri());
wp_register_script( 'custom-script', get_template_directory_uri() . '/js/bootstrap.min.js', array( 'jquery' ) );
wp_register_script( 'custom-script', get_template_directory_uri() . '/js/imagesloaded.pkgd.min.js', array( 'jquery' ) );
wp_register_script( 'custom-script', get_template_directory_uri() . '/js/jquery.js', array( 'jquery' ) );
wp_register_script( 'custom-script', get_template_directory_uri() . '/js/masonry.pkgd.min.js', array( 'jquery' ) );
wp_register_script( 'custom-script', get_template_directory_uri() . '/js/offcanvas.js', array( 'jquery' ) );
wp_enqueue_style('style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts','catalog');
register_nav_menus(array(
'primary' => __('Primary Menu'),
'footer' => __('Footer Menu'),
));
?>
So I don't know whats really going wrong here cause I've checked everything and it looks fine. Here's my folder structure:
theme_folder
css
bootstrap.min.css
images
js
bootstrap.min.js
imagesloaded.pkgd.min.js
jquery.js
masonry.pkgd.min.js
offcanvas.js
But after all this I get this as result which means they have not beed loaded:
Problem You are register a script but not enqueue.
Solution: If you are register then you have to enqueue. wp_enqueue_style() - For css enqueue wp_enqueue_script()- For JS enqueue
Updated code
Recommendation
Always Prefer CDN for css and js like jquery,bootstrap etc.