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

'Word press theme development' white screen. Turned debug on: syntax error, unexpected 'function' (T_FUNCTION)

wp newb here..

I'm following the wp theme dev course to the tee and trying to create the custom theme with the project files.

I've figured out that my error is in my bottom half of my functions.php, specifially the "function wpt_theme_js() {" line.

I can't find any errors in the syntax so i'm not sure what's going on..? I've tried commenting out each line and still didn't find the error. When I comment that whole block out, my local wp back end is up and running.

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.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' );

Thanks in advance for the help!

12 Answers

I found the error! I was simply missing a simple ";" after my "add_action" code.

Thanks for the effort and help!

Agustin Grube
Agustin Grube
39,278 Points

That's great. Glad you worked it out. I was setting-up a local site on my HD using a Bitnami Local WordPress Stack to try to recreate it, but I ran into problems. Now my local AMPPS install and local development sites are not working. So, I've been trying to figure out why.

I wish I could have been more helpful.

Agustin Grube
Agustin Grube
39,278 Points

do you have the

'/js/foundation.js' 

or the

'/js/foundation.min.js'

in the .js folder?

change to the foundation.min.js to see if that will worK

Make sure there isn't extra blank lines in your functions.php file after the closing php tag.

Thanks for the replies but no answer yet.. I tried putting in the "min" and that helped but my function "custom name" theme_js is still breaking the page. It's on my line 14 if that helps.

wish I could screen shot it..

Agustin Grube
Agustin Grube
39,278 Points

(assuming you are following the class code) Line 14 is the nav menu. Does your code look like this:

<?php 

add_theme_support( 'menus' );
add_theme_support( 'post-thumbnails' );

function wpt_excerpt_length( $length ) {
    return 16;
}
add_filter( 'excerpt_length', 'wpt_excerpt_length', 999 );

function register_theme_menus() {

    register_nav_menus(
        array(
            'primary-menu'  => __( 'Primary Menu', 'treehouse-portfolio' )          
        )
    );

}
add_action( 'init', 'register_theme_menus' );


function wpt_create_widget( $name, $id, $description ) {

    register_sidebar(array(
        'name' => __( $name ),   
        'id' => $id, 
        'description' => __( $description ),
        'before_widget' => '<div class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<h2 class="module-heading">',
        'after_title' => '</h2>'
    ));

}

wpt_create_widget( 'Page Sidebar', 'page', 'Displays on the side of pages with a sidebar' );
wpt_create_widget( 'Blog Sidebar', 'blog', 'Displays on the side of pages in the blog section' );


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' );

there is a difference between register_nav_menus (plural) and register_nav_menu (singular)

http://codex.wordpress.org/Function_Reference/register_nav_menu

At this point, I'm not even at the menu part. Here's what my functions.php file looks like:

<?php

function wpt_theme_styles() {

wp_enqueue_style( 'foundation_css', get_template_directory_uri() . '/css/foundation.min.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_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' );

?>

Agustin Grube
Agustin Grube
39,278 Points

Just checking. Do you have the foundation.min.js file in the js folder?

/js/foundation.min.js

Yep. It's in my "js" folder.

It's the "function wpt_theme_js()" line that's causing an error. Thanks for the effor, Agustin. ;)

Agustin Grube
Agustin Grube
39,278 Points

I am aware. You can name the function anything you want, it's the wp_enqueue_script that is important here and what's kicking it to the curb in that line. Now it's bugging me.

Try it without so many spaces:

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');
Agustin Grube
Agustin Grube
39,278 Points

I think the problem is with the enqueue above the foundation enqueue and the name handles.

First drop the _js on each line and try that, if not working try adding an empty array to modernizer like this:

function wpt_theme_js () {
    wp_enqueue_script('modernizr', get_template_directory_uri().'/js/modernizr.js',array(),'',false);
    wp_enqueue_script('foundation', get_template_directory_uri().'/js/foundation.min.js',array('jquery'),'',true);
    wp_enqueue_script('main', get_template_directory_uri().'/js/app.js',array('jquery','foundation_js'),'',true);
}
add_action('wp_enqueue_scripts', 'wpt_theme_js');

tried both, no spaces and dropping the "_js" and it's still not working.

here's the error message:

"Parse error: syntax error, unexpected 'function' (T_FUNCTION) in /Users/JackVu/Sites/jackvu.com/wp-content/themes/jvtheme/functions.php on line 14"

It's the "function wpt_theme_js" line... ?