Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Fernando Jimenez
PLUS
Fernando Jimenez
Courses Plus Student 7,720 Points

Why does Jquery work with Wordpress using jQuery('example') and not with $('example')???

everytime I run jquery on the console with Wordpress it doesn't understand the short version $

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Fernando Jimenez Hi there! Steven Parker is absolutely correct. As you may know, WordPress is written in PHP. All PHP variables start with the dollar sign $. So when you use that, it thinks you're trying to use a PHP variable, not a jQuery object.

Hope this helps! :sparkles:

Steven Parker
Steven Parker
216,136 Points

I wouldn't expect that confusion with PHP variables would be an issue since any php code would likely be in a separate file and contained within identifying tags ("<?php /* PHP code in here */ ?>").

Steven Parker
Steven Parker
216,136 Points

I haven't done Wordpress programming, but it could be that it uses "$" for something else. It's just an alias after all. You could try resetting it, but that might break something if it was using it.

Or you could create your own shorthand ("var jq = jQuery").