Styles and Scripts not loading
-
Hello. I am trying to load styles and scripts to my theme and it is not working. I am developing locally so I have no link to provide you. Below is code I added to functions.php. I am creating a custom theme.
function add_required_scripts() { wp_register_script('bootstrap', get_template_directory_uri() . 'js/bootstrap.min.js', array('jquery')); // enqueue the script wp_enqueue_script('bootstrap'); } add_action('wp_enqueue_scripts', 'add_required_scripts'); function add_required_styles() { wp_register_style('bootstrap', get_template_directory_uri().'css/bootstrap.css'); wp_enqueue_style('bootstrap'); } add_action( 'wp_enqueue_scripts', 'add_required_styles' );
Just before the closing </head> tag I have added <?php wp_head() ?>, The admin bar is showing on the top of the page so I know thats working.
I also did a test to see if my functions.php file is loading by adding this to functions.php:
<?php echo 'functions.php has been included'; exit; ?>
Upon looking at the front of the site I get my message so I know functions.php has loaded as well, so I removed my test code.
It is not that I am including the wrong path to my files either, when I look at the page resources there sre no style sheets or scripts loading at all other than what is automatically loaded by WordPress.
I used the code above for loading styles and scripts in my first WordPress project (this is my second WP project) and it worked fine. Not sure what I am missing. Any help would be greatly appreciated.
Cheers
- The topic ‘Styles and Scripts not loading’ is closed to new replies.