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

JavaScript

Wordpress Theme Doesn't Load Flexslider Files

Here is my code from the Wordpress Theme Tutorial. I posted this before and realized it's in my functions.php since its actual files not loading. It is loading all my other documents and the file path is correct. Thoughts?

<?php

add_action( 'wp_enqueue_scripts', 'theme_js' );

add_action( 'wp_enqueue_scripts', 'theme_styles' );


//Load the Theme CSS
function theme_styles() {

    wp_enqueue_style( 'normalize', get_template_directory_uri() . '/css/normalize.css' );
wp_enqueue_style( 'grid', get_template_directory_uri() . '/css/grid.css' );
wp_enqueue_style( 'googlefonts', 'http://fonts.googleapis.com/css?family=Sorts+Mill+Goudy:400,400italic'     ); 
wp_enqueue_style( 'main', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'social', get_template_directory_uri() . '/css/webfonts/ss-social.css' );

wp_register_style( 'flex-stylesheet', get_bloginfo('stylesheet_directory'). '/css/flexslider.css', array(), '', 'all'     );
if( is_home() ) {
    wp_enqueue_style('flex-stylesheet');
}

}

//Load the Theme JS
function theme_js() {

wp_register_script( 'flexslider', get_bloginfo('stylesheet_directory').'js/jquery.flexslider-min.js',     array('jquery'));
wp_register_script('flexslider-init', get_bloginfo('stylesheet_directory').'js/flexslider-init.js', array('jquery', 'flexslider'));
if( is_home() ) {
    wp_enqueue_script( 'flexslider' );
    wp_enqueue_script( 'flexslider-init' );
}

}

wp_enqueue_script( 'theme_js', get_template_directory_uri() . '/js/theme.js', array('jquery'), '', true );

//Enable custom menus
add_theme_support( 'menus' );

function create_widget( $name, $id, $description ) {
$args = array(
    'name'          => __( $name ),
    'id'            => $id,
    'description'   => $description,
    'before_widget' => '',
    'after_widget'  => '',
    'before_title'  => '<h5>',
    'after_title'   => '</h5>' 
);

register_sidebar( $args );

}

create_widget( 'Left Footer', 'footer_left', 'Displays in the bottom left of footer');

create_widget( 'Middle Footer', 'footer_middle', 'Displays in the bottom middle of footer');

create_widget( 'Right Footer', 'footer_right', 'Displays in the bottom right of footer');


?>

2 Answers

Gautam Thapar
Gautam Thapar
5,265 Points

Seems like the condition is not met. Try without the condition and see if it works.

Are you using a static page as your home page? if yes, then you need to use is_front_page() in your conditional statement.

That worked! Maybe Zac can comment on this, but why did register script break flexslider?

Gautam Thapar
Gautam Thapar
5,265 Points

I rechecked your code and you seem to be missing '/' before js/jquery.flexslider-min.js & js/flexslider-init.js.

wp_register_script( 'flexslider', get_bloginfo('stylesheet_directory').'js/jquery.flexslider-min.js',     array('jquery'));
wp_register_script('flexslider-init', get_bloginfo('stylesheet_directory').'js/flexslider-init.js', array('jquery', 'flexslider'));
Gautam Thapar
Gautam Thapar
5,265 Points

Preferable way to include template directory uri is by using get_template_directory_uri() for parent theme and get_stylesheet_directory_uri() for child themes.

In both cases trailing slash in not added after the url.

This all worked. Thanks!