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 WordPress Theme Development WordPress Header and Footer Templates Porting existing headers and footers into WordPress

Nathan Barlcay
Nathan Barlcay
4,547 Points

Functions file does not seem to help load the page correctly. Looks plain with no styling applied...

I'm having trouble loading the page correctly, the code appears to be correct in relation to the video tutorial?.

Can someone help view the code and provide some pointers to get me back on track?? ta

If I add the code below I cannot load the page altogether...

<?php

function wpt_theme_styles() {

    wp_enqueue_style( 'foundation_css', get_template_directory_uri() . '/css/foundations.css');
    wp_enqueue_style( 'normalize.css', get_template_directory_uri() . '/css/normalize.css');
    wp_enqueue_style( 'normalize.css', 'http://fonts.googleapis.com/css?family=Asap:400,700,400italic,700italic');
    wp_enqueue_style( 'main_css', get_template_directory_uri() . 
        '/style.css');




}

    add_action('wp_enqueue_scripts', 'wpt_theme_styles' );

    function wpt_theme_js() {

        wp_enqueue_style( 'modernizr_js', get_template_directory_uri() . '/js/modernizr.js', '', '', false );
        wp_enqueue_style( 'foundation_js', get_template_directory_uri() . '/js/foundation.js', array('jquery)', '', true );
            wp_enqueue_style( 'main_js', get_template_directory_uri() . '/js/app.js', array('jquery, 'foundation_js'), '', true );
    }

    add_action( 'wp_enqueue_scripts', 'wpt_theme_js' );

?>

However if I add the change below we can load but with no styling applied to the page..

<?php

function wpt_theme_styles() {

    wp_enqueue_style( 'foundation_css', get_template_directory_uri() . '/css/foundations.css');
    wp_enqueue_style( 'normalize.css', get_template_directory_uri() . '/css/normalize.css');
    wp_enqueue_style( 'normalize.css', 'http://fonts.googleapis.com/css?family=Asap:400,700,400italic,700italic');
    wp_enqueue_style( 'main_css', get_template_directory_uri() . 
        '/style.css');




}

add_action( 'wp_enqueue_scripts', 'deregister_script' );
function deregister_script() {
   wp_deregister_script('jquery');
   wp_register_script('jquery', ('//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js'), false, '', true );
}

    add_action( 'wp_enqueue_scripts', 'wpt_theme_js' );

?>

Any advice would be great?!

Thanks, NB

12 Answers

xenon thong
xenon thong
3,952 Points

@Nathan Barlcay

You've hooked 'wpt_theme_styles' twice. You didn't hook 'wpt_theme_js' onto 'wp_enqueue_scripts'.

Also, inside the wpt_theme_js() function, you're calling wp_enqueue_style() instead of wp_enqueue_script()

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

This is what I'm seeing from the final-theme project downloads:

<?php

function wpt_theme_styles() {

    wp_enqueue_style( 'foundation_css', get_template_directory_uri() . '/css/foundation.css' );
    //wp_enqueue_style( 'normalize_css', get_template_directory_uri() . '/css/normalize.css' );
    wp_enqueue_style( 'googlefont_css', 'http://fonts.googleapis.com/css?family=Asap:400,700,400italic,700italic' );
    wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );

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

function wpt_theme_js() {

    wp_enqueue_script( 'modernizr_js', get_template_directory_uri() . '/js/modernizr.js', '', '', false );  
    wp_enqueue_script( 'foundation_js', get_template_directory_uri() . '/js/foundation.min.js', array('jquery'), '', true );
    wp_enqueue_script( 'main_js', get_template_directory_uri() . '/js/app.js', array('jquery', 'foundation_js'), '', true );        

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

?>
Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Couple of things to check:

  • You have a css folder with the files referenced
  • You have a style.css with styles in it

When you open your source code, what is the URL to the style.css file? Does this file load? Does the URL look correct?

Nathan Barlcay
Nathan Barlcay
4,547 Points

If I follow your lead here it appears the style.css file has a url that find a path through wp-includes and not wp-content. If this is the issue what would be the best solution to remedy this??

Any help would be greatly appreciated?

Thanks NB

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Hmmm, from what you posted it does not look like the style.css is in the source code at all.

What happens when you update your functions.php file to just this:

<?php
function wpt_theme_styles() {

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

}
add_action('wp_enqueue_scripts', 'wpt_theme_styles' );
?>

Then do you see a link to the style.css file in your source code?

What if you update your code to the following?

<?php
function wpt_theme_styles() {

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

}
add_action('wp_enqueue_scripts', 'wpt_theme_styles' );
?>
Nathan Barlcay
Nathan Barlcay
4,547 Points

I'm still having an issue running this script below:-

    ```wp_enqueue_style( 'foundation_js', get_template_directory_uri() . '/js/foundation.min.js', array('jquery)', '', true );```

Seems to be part of the same problem and looking like a continuation of the original issue in this question?. Any ideas??

Thanks, NB

Nathan Barlcay
Nathan Barlcay
4,547 Points

At the moment I'm struggling to get the "The wp_nav_menu Function" to work and the JavaScript doesn't seem to be loading for me. I can get the page to load without the static template..

function wpt_theme_styles() {


    wp_enqueue_style( 'foundation_css', get_stylesheet_directory_uri() . '/css/foundation.css');
    wp_enqueue_style( 'googlefont.css', 'http://fonts.googleapis.com/css?family=Asap:400,700,400italic,700italic');
    wp_enqueue_style( 'main_css', get_stylesheet_directory_uri() .  '/style.css');

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

function wpt_theme_js() {


        wp_enqueue_style( 'modernizr_js', get_stylesheet_directory_uri() . '/js/modernizr.js', '', '', false );

    }

    add_action('wp_enqueue_scripts', 'wpt_theme_styles');


?>```

However I get a series of faults like below>>>
```[Warning] Invalid CSS property declaration at: * (foundation.css, line 78, 110, 130, 140, 1518, 2182, 2807, 3023 )```

 but when I use this code I get an error>>>

```<?php
function wpt_theme_styles() {


    wp_enqueue_style( 'foundation_css', get_stylesheet_directory_uri() . '/css/foundation.css');
    wp_enqueue_style( 'googlefont.css', 'http://fonts.googleapis.com/css?family=Asap:400,700,400italic,700italic');
    wp_enqueue_style( 'main_css', get_stylesheet_directory_uri() .  '/style.css');

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

function wpt_theme_js() {


        wp_enqueue_style( 'modernizr_js', get_stylesheet_directory_uri() . '/js/modernizr.js', '', '', false );
        wp_enqueue_style( 'foundation_js', get_stylesheet_directory_uri() . '/js/foundation.min.js', array('jquery)', '', true );
        wp_enqueue_style( 'main_js', get_stylesheet_directory_uri() . '/js/app.js', array('jquery, 'foundation_js')', '', true );
    }

    add_action('wp_enqueue_scripts', 'wpt_theme_styles');


?>```

When checking the debugger for errors I get this message>>>

```[Error] Failed to load resource: the server responded with a status of 500 (Internal Server Error) (contact-us, line 0)```

I've a mac pro, MAMP, MySQL setup. What is the best route around this issue??
xenon thong
xenon thong
3,952 Points

You've hooked 'wpt_theme_styles' twice. You didn't hook 'wpt_theme_js' onto 'wp_enqueue_scripts'. Also, inside the wpt_theme_js() function, you're calling wp_enqueue_style() instead of wp_enqueue_script()

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Try switching the JS code to use

get_template_directory_uri()

Nathan Barlcay
Nathan Barlcay
4,547 Points

No that didn't work but wasn't this the code removed originally and replaced by your suggestion?! As indicated in this thread, we are struggling to move forward with the rest of the course as the js files don't seem to be loading.

Same question no answer as yet. I also note that your previous comments did not load onto this page which is why I made contact directly. It seems I get a prompt response that way and unable to get one via this forum. Is there an issue with the forum system??

Either way I realise you are not around tomorrow and I would really like to press on with the rest of your course as I have a project to start asap and it would be really helpful if you could help troubleshoot this with me.

I await your response...

Regards, NB

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Would you by chance be able to post this up somewhere could take a look at?

my css doesnt work too :/

xenon thong
xenon thong
3,952 Points

Hi Karim, would you be able to provide more information? Ie your code or code structure