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 - Where is Jquery file ?

I have a question where I need to put Jquery file ? As during video course there is only mention that we need to put array(jquery) for the addons that we load after jquery... I`m little bit confused

I getting this kind of error: Parse error: syntax error, unexpected 'jquery' (T_STRING) in

D:\Workspace\localhost\xampp\htdocs\Projects\sandbox\wp-content\themes\theme_name\functions.php on line 17

<?php

//Loading all styles
function wpt_theme_styles(){
    wp_enqueue_style('normalize_css' , get_template_directory_uri() . '/ext-addons/normalize/normalize.css' ); // Normalize
    wp_enqueue_style('bootstrap_css' , get_template_directory_uri() . '/ext-addons/bootstrap/css/bootstrap.min.css' ); // Bootstrap
    wp_enqueue_style('main_css' , get_template_directory_uri() . '/style.css'); // Main CSS
    wp_enqueue_style('main_css' , 'http://fonts.googleapis.com/css?family=Montserrat:400,700'); // Fonts - Montserrat
    wp_enqueue_style('main_css' , 'http://fonts.googleapis.com/css?family=Roboto:400,400italic,700,700italic'); // Fonts - Montserrat
}
add_action('wp_enqueue_scripts','wpt_theme_styles');

//Loading all js-plugins
function wpt_theme_js(){
    // name , path , dependence , version , footer/header (t/f)
    wp_enqueue_script('modernizr_js' , get_template_directory_uri() . 'ext-addons/modernizr/modernizr.js' , '' , '' , false); // Modernizr 
    wp_enqueue_script('bootstrap_js' , get_template_directory_uri() . 'ext-addons/bootstrap/js/bootstrap.min.js' , 'array('jquery')' , '' , true); // Bootstrap
    wp_enqueue_script('main_js' , get_template_directory_uri() . 'scripts.js' , 'array('jquery','bootstrap_js')' , '' , true); // Main JS
}
add_action('wp_enqueue_scripts','wpt_theme_js');
?>

I know that I don`t have a jquery loaded and thats why... but where I need to put this ?

// Do I Need to put it in queue also ?

17 Answers

Davide Pugliese
Davide Pugliese
4,091 Points

OK this might be the problem:

'array('jquery','bootstrap_js')'

Rewrite it as 'array("jquery","bootstrap_js")'

Basically the PHP parser if I have had the right insight, does not recognize the beginning and the end of that array expression.

Therefore it stops evaluating here:

'array(' and it asks itself: Array what? What's the array?

Davide Pugliese
Davide Pugliese
4,091 Points

Hello, I worked a lot with Wordpress over the summer. In the latest versions of Wordpress the jQuery libraries have been included in Wordpress itself and they are retrieved through CDN, this is why you do not see them anymore in functions.php. If you have Sublimetext you can find pretty easily anything you want inside files by using ctrl+shift+f

In this case after pressing ctrl+shift+f, you will write jquery and then you will select the folder containing Wordpress.

Since when customizing themes you will need to dig a lot inside files, I think this is the best suggestion I can give you.

ahh thanks ;) Thats why they didn`t add it between head ;) Great

Davide Pugliese
Davide Pugliese
4,091 Points

Actually you should find it in the

 portion when looking at the source code of the page when you view the web site in your browser, but it's called in another .php file.

hmm so how can i check if there is a jquery loaded or not ? simply just try to use some jquery code and check if it execute ?

as I have wordpres 4.1 // and can`t find any phrase JQUERY inside of index file // and thats why it is not loading my bootstrap etc

Davide Pugliese
Davide Pugliese
4,091 Points

I checked for you on Stack Overflow, and actually I remembered correctly http://stackoverflow.com/questions/22234862/how-to-load-jquery-into-wordpress-properly

There must be something else going on I think if you cannot see jquery loaded.

I would deactivate all of the plugins just to be sure there are not conflicts going on.

You can try also to load a default theme just to be sure that you are loading Bootstrap properly.

This is part of a normal debugging routine in cases like this.

Unfortunately this is part of the job and I have lost tons of blood to learn these things over the summer. :)

Davide Pugliese
Davide Pugliese
4,091 Points

One more useful suggestion is to activate the debugging output in Wordpress by writing define( 'WP_DEBUG', true ); in wp-config.php and also you may want to give a shot at Netbeans + Xdebug to debug PHP locally.

Also, considering the increasing number of servers using NGINX, you might worth considering using NGINX locally, if you fancy using NGINX, using the package Wpnxm which is like Wamp to Apache.

So ok jquery is build somewhere in worpdress // checked if as Jquery scripts are working good...

second thing is I have a problem there

<?php

//Loading all styles
function wpt_theme_styles(){
    wp_enqueue_style('normalize_css' , get_template_directory_uri() . '/ext-addons/normalize/normalize.css' ); // Normalize
    wp_enqueue_style('bootstrap_css' , get_template_directory_uri() . '/ext-addons/bootstrap/css/bootstrap.min.css' ); // Bootstrap
    wp_enqueue_style('main_css' , get_template_directory_uri() . '/style.css'); // Main CSS
    wp_enqueue_style('main_css' , 'http://fonts.googleapis.com/css?family=Montserrat:400,700'); // Fonts - Montserrat
    wp_enqueue_style('main_css' , 'http://fonts.googleapis.com/css?family=Roboto:400,400italic,700,700italic'); // Fonts - Montserrat
}
add_action('wp_enqueue_scripts','wpt_theme_styles');

//Loading all js-plugins
function wpt_theme_js(){
    // name , path , dependence , version , footer/header (t/f)
    wp_enqueue_script('modernizr_js' , get_template_directory_uri() . 'ext-addons/modernizr/modernizr.js' , '' , '' , false); // Modernizr 
    wp_enqueue_script('bootstrap_js' , get_template_directory_uri() . 'ext-addons/bootstrap/js/bootstrap.min.js' , 'array('jquery')' , '' , true); // Bootstrap
    wp_enqueue_script('main_js' , get_template_directory_uri() . 'scripts.js' , 'array('jquery','bootstrap_js')' , '' , true); // Main JS
}
add_action('wp_enqueue_scripts','wpt_theme_js');
?>

'jquery' is not definied

Davide Pugliese
Davide Pugliese
4,091 Points

However, it's a great thing you are starting to use Bootstrap as it is a clean and well documented framework. Keep in mind however that I am switching from using frameworks to trying to use no framework at all or at least removing, when the website is completed, all the css that is not actually used. Why? Because Google Page Speed penalizes the use of unused CSS. I created this website last summer: http://www.sosamsterdam.com and since I am getting back to Bucharest, and maybe I will try to do something like that over there as well, I will switch to Laravel + Wordpress. For projects like that Wordpress becomes a little bit heavy. This is why I am here, learning good foundations of PHP + Laravel.

Davide Pugliese
Davide Pugliese
4,091 Points

OK, I see you have scripts.js loaded after bootstrap, so I presume your problems is inside some additional scripts you have in scripts.js?

I don`t have any additional scripts, script file looks like :

//Jquery no conflict

jQuery(document).ready(function($){
    //jquery code
});
Davide Pugliese
Davide Pugliese
4,091 Points

OK, read my previous post. :)

BRING HIM A BEER ! YOU were RIGHT ;)

Davide Pugliese
Davide Pugliese
4,091 Points

This is my Linkedin account, I should update it however with the latest info: https://www.linkedin.com/profile/view?id=200093607

There is still the company I was opening... long story... basically I have not found find yet the right people to work with. I have to be the front end developer + PHP developer + Web Designer of my own company. It's hard to find people you can rely on.

Davide Pugliese
Davide Pugliese
4,091 Points

Romania is a very good place indeed now in Europe to start up a business as you can have funds also for e-commerce websites. But it's hard to find people to work with. The nation is at the third place in Europe for the quality of the Internet connections and in almost every house in Bucharest you have optic fiber cables. There are the headquarters of Microsoft, Oracle, Avira, Ubisoft and many other companies. Ubisoft games are not produced in Canada anymore but they are outsourced to Romanian companies to keep low the production costs. So let's get back learning, there are plenty of jobs waiting for me. :)

sorry but cant reach yours account as we dont have any similar contacts ;( I have the same story, trying to make my landing page now and code it :) I got GFX + Customer service lady ;) and just trying to see what will happens ;)

Davide Pugliese
Davide Pugliese
4,091 Points

If you give me your id on Linkedin I will add you.

https://www.linkedin.com/in/krzysztofcieslik ( This is my temporrary account on treehouse )