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

Katherine Elsken
Katherine Elsken
2,330 Points

Problem loading scripts in Genesis

I've been working on a project using Genesis and this is my first time using it. I'm having problems loading any kind of custom java scripts or jquery into my child theme.When I use the wp_enqueue_scripts function, my custom stylesheets load just fine, but not any other kind of scripts. I'm about ready to pull my hair out because this is the last major issue I need to fix in my theme

4 Answers

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

See if this helps (from the Bootstrap course):

function theme_styles() {

    wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );

}
add_action( 'wp_enqueue_scripts', 'theme_styles' );

function theme_js() {

    wp_enqueue_script( 'bootstrap_js', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '', true );

}
add_action( 'wp_enqueue_scripts', 'theme_js' );
Katherine Elsken
Katherine Elsken
2,330 Points

This is what my code looks like for my javascript . sure enough it loads on the page in the source, but it still doesn't work.

// Register responsive menu script
add_action( 'wp_enqueue_scripts', 'sophie_enqueue_scripts' );
/**
 * Enqueue responsive javascript
 * @author Ozzy Rodriguez
 * @todo Change 'prefix' to your theme's prefix
 */

function sophie_enqueue_scripts() {

  wp_enqueue_script( 'sophie-responsive-menu', get_stylesheet_directory_uri() . '/lib/js/responsive-menu.js', array( 'jquery' ), '', true ); // Change 'prefix' to your theme's prefix

}
Spencer Putnam
Spencer Putnam
2,813 Points

Hi Katherine. I've run into the exact same problem customizing themes on the Genesis framework. I've taken a lot of great suggestions from Genesis devs and meticulously combed through by code but still, no luck loading scripts in certain cases.

Did Zac's code help solve your problem? Or did you find any other resources online that answer some of the Genesis-related questions? Thanks!

Jonathan Seligsohn
Jonathan Seligsohn
23,116 Points

Katherine Elsken, are your JS files using jquery? If so, are you aware of jQuery, no-conflict-mode? Looks something like this:

jQuery(document).ready(function($) { // Code here will be executed on document ready. Use $ as normal. });

Otherwise, you can't use the '$' as WP thinks it refers to something else. See here for more info: http://matthewruddy.com/using-jquery-with-wordpress/

Saqib Ali
Saqib Ali
3,686 Points

Has the situation improved since this discussion began two years ago? I'm in a similar situation when using Genesis themes.