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

Kristin Koch
Kristin Koch
394 Points

CSS and Javascript won't load onto site

So I've created my header.php and added this function

    <?php wp_head(); ?>

but the css and javascript won't load to the site. I've gone over my functions.php code several times and can't find any errors. Any help is appreciated.

<?php 

function wpwm_theme_styles() {

    wp_enqueue_style( 'googlefont_css', 'https://fonts.googleapis.com/css?family=Permanent+Marker' );
    wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );


}

add_action( 'wp_enqueue_scripts', 'wpwm_theme_styles' );

function wpwm_theme_js() {

    wp_enqueue_script( 'main.js', get_template_directory_uri() . '/main.js', array('jquery'), ' ' , false);

}

add_action( 'wp_enqueue_scripts', 'wpwm_theme_js' );

?>

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Have look at your actions codes.

add_action( 'wp_enqueue_scripts', 'wpwm_theme_styles' );
add_action( 'wp_enqueue_scripts', 'wpwm_theme_js' );

In the first one it loojks liek you're trying to enqueue a script file when you want a style sheet. Looking at the documentation the scripts hook should work but you're only trying to enqueue styles on the first one.

So my suggestions are to change 'wpwm_theme_styles to wpwm_theme_scripts

Or changing your hooks to

add_action( 'wp_enqueue_script', 'wpwm_theme_styles' );
add_action( 'wp_enqueue_script', 'wpwm_theme_js' );
Kristin Koch
Kristin Koch
394 Points

I tried both suggestions and it didn't work.

So should you still use

'wp_enqueue_style'

when you are loading up a css page in the action codes

add_action( 'wp_enqueue_style', 'wpwm_theme_styles' );
Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Yes I would do that.

I've been trying to find the code I used to do this for the Bootstrap to JS course but I'm off my computer at the moment.

But I'm positive it should work with wp_enqueue_style and wp_enqeue_script should both work, for stylesheets and scripts.

Kristin Koch
Kristin Koch
394 Points

Dot! my fault. I named it function.php and not functions.php. That one s made the whole difference in the world