Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJesse Ward
6,275 PointsScripts Not Showing
I'm having trouble getting the scripts to show up in the source code. I even downloaded the project files and replaced all of my files with the ones given. It's still not working for me. What am I doing wrong?!
<?php
function theme_styles() {
wp_enqueue_style( 'bootstrap_css', get_template_directory_uri() . '/css/bootstrap.min.css' );
wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'theme_styles' );
function theme_js() {
global $wp_scripts;
wp_register_script( 'html5_shiv', 'https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js', '', '', false );
wp_register_script( 'respond_js', 'https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js', '', '', false );
$wp_scripts->add_data( 'html5_shiv', 'conditional', 'lt IE 9' );
$wp_scripts->add_data( 'respond_js', 'conditional', 'lt IE 9' );
wp_enqueue_script( 'bootstrap_js', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '', true );
}
?>
<hr>
<footer>
<p>© Company 2014</p>
</footer>
</div> <!-- /container -->
<?php wp_footer(); ?>
</body>
</html>
3 Answers
Ryan Field
Courses Plus Student 21,242 PointsHi, Jesse.
You need to add the following line to be able to add the scripts to your page:
add_action('wp_enqueue_scripts', 'theme_js');
Jesse Ward
6,275 PointsI figured it out already. The functions.php file is incomplete in the project files section. It was missing:
add_action( 'wp_enqueue_scripts', 'theme_js' );
Jesse Ward
6,275 PointsThanks Ryan! I figured that out right before you posted! I believe my original functions.php wasn't working because of a typo or something along those lines.
Ryan Field
Courses Plus Student 21,242 PointsNo problem! I saw you post it as soon as I posted it! :)
ammarkhan
Front End Web Development Techdegree Student 21,661 Pointsammarkhan
Front End Web Development Techdegree Student 21,661 PointsMy code isn't working. I tried the same code. How can i debug or know the problem cause?