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

JavaScript

Fernando Jimenez
PLUS
Fernando Jimenez
Courses Plus Student 8,455 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
230,248 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
230,248 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").