I’m working on WordPress theme using Bootstrap on localhost.
I have load the CSS files correctly and I have load the js files using the right way but for some reasons js scripts is not working.
Here is my index.php
<?php get_header(); ?>
<?php get_footer(); ?>
Here is my header.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href = "<?php bloginfo(stylesheet_url); ?>" rel = "stylesheet">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Start Bootstrap</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
<a href="#about">About</a>
</li>
<li>
<a href="#services">Services</a>
</li>
<li>
<a href="#contact">Contact</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
Here is my footer.php
<script src= "<?php get_template_directory(); ?>/js/bootstrap.js"></script>
</body>
</html>
This problem drives me CRAZY!
I spent 2 hours searching for solution but nothing!
So what is the problem guys?
You can use it for including your scripts
And For stylesheet you have to use this function.
Please refer wordpress documentation for include your script into footer.
This the right way to include your script and styles.
And please add wp_head(); functions in your header to load script and styles.
Put this code in your “functions.php” file to enqueue “/css/bootstrap.min.css”, “/style.css” and your “/js/bootstrap.js”:
Keep note, you need to set the last parameter of
wp_enqueue_script
totrue
to place your ‘/js/bootstrap.js’ before the</body>
end tag. For more info visit this link.You missed
echo
. You must print what the functionget_template_directory_uri()
returns like here:<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/bootstrap.js"></script>
After that your js will work flawless.