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

Marina Ferreira
Marina Ferreira
6,276 Points

Linking JavaScript

Hi, I'm following the WordPress adventure and for some reason I'm not able to link my flexslider.js script to the footer of my website. Here is my code:

functions.php:

<?php

    //Load 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('flexslider', get_template_directory_uri() . '/css/flexslider.css');
        if (is_page('home'))
        {
            wp_enqueue_style('flexslider');
        }
    }

    function theme_js()
    {
        wp_register_script('flexslider', get_template_directory_uri() . '/js/flexslider.js', array('jquery'), '', true );
        if (is_page('home'))
        {
            wp_enqueue_script('flexslider');
        }
    }

    add_action('wp_enqueue_scripts', 'theme_js');

    add_action('wp_enqueue_scripts', 'theme_styles');

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

?>

I get only this:

< script type='text/javascript' src='http://localhost/allisongrayce.com/wp-includes/js/jquery/jquery.js?ver=1.8.3'></script>

linked to the header.

If I change this line on my code from:

wp_register_script('flexslider', get_template_directory_uri() . '/js/flexslider.js', array('jquery'), '', true );

to

wp_register_script('flexslider', get_template_directory_uri() . '/js/flexslider.js', array('jquery'));

I get

< script type='text/javascript' src='http://localhost/allisongrayce.com/wp-includes/js/jquery/jquery.js?ver=1.8.3'></script>

< script type='text/javascript' src='http://localhost/allisongrayce.com/wp-content/themes/wpportfolio/js/flexslider.js?ver=3.5.2'></script>

but both linked to the header...

Any thoughts??

4 Answers

Kevin Korte
Kevin Korte
28,149 Points

Do you have the

<?php wp_footer(); ?>

hook in your footer.php?

QI ZHENG
QI ZHENG
11,913 Points

I have the same problem...:(

Renan Freitas
Renan Freitas
4,142 Points

I don't know if this wil solve it, but you didn't do the: <blockquote> wp_enqueue_script('theme_js'); </blockquote> below the enqueue script of the flexslider, as it's said on the video. also, since you didn't register it beforehand, you'll have to put after it the: , get_template_directory_uri() . '/js/flexslider.js', array('jquery'), '', true at the end of it.

Marina Ferreira
Marina Ferreira
6,276 Points

I did registered it, and the wp_enqueue_script('theme_js') is below the function.

Thank you for all your answers, I actually started everything again and I got it right.