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 trial

WordPress From Bootstrap to WordPress Setup a Bootstrap Theme Add Bootstrap JS via the functions.php File

How to Include Additional Script in Bootstrap Jumbotron

I followed this lesson just fine, so this is more of an expansion. Since this video was made the Jumbotron template has been updated with an additional script to handle a viewport bug for Windows 8 on the Surface machine. I followed the link in the source code to get the script and saved it in my /js file.

My question is, should this be called as a wp_register_script or as a wp_enqueue_script since it is only used conditionally? My feeling is that it should be wp_register_script, but I am curious to know what the community thinks. I would like to use this theme as a launchpad going forward, so having this script seems important. I do not have a Windows 8 Surface to test on, so when I run it on my Windows 7 machine, it doesn't show up.

1 Answer

Jaime Rios
PLUS
Jaime Rios
Courses Plus Student 21,100 Points

I had the same trouble and the solution I found was to copy and paste the "bootstrap.min.js line" like this

      ```php

<?php 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 );

  //Those are the plugins
  wp_enqueue_script('easing_js', get_template_directory_uri() . '/js/jquery.easing.min.js', array('jquery'), '', true );
  wp_enqueue_script('fittext_js', get_template_directory_uri() . '/js/jquery.fittext.js', array('jquery'), '', true );
  wp_enqueue_script('wow_js', get_template_directory_uri() . '/js/wow.min.js', array('jquery'), '', true );
  wp_enqueue_script('creative_js', get_template_directory_uri() . '/js/creative.js', array('jquery'), '', true );

};

add_action('wp_enqueue_scripts', 'theme_js'); ?>

      ```