how to make jQuery dollar sign work with WordPress
- This topic is empty.
- You must be logged in to reply to this topic.
May 2024 only! Join our Discord free of charge.
I have seen this problem sometimes. The dollar sign shorthand doesn’t work and the script will simply not load. I have read to change “$” to be “jQuery” for all instance, is this really necessary? very messy…..
for example, in my Child Theme files.
Here’s a good blog post you might want to check out:
https://dannyda.com/2022/05/22/how-to-use-jquery-where-we-cant-use-the-dollar-sign-does-not-work/
great cheers mate.
You must use the compatibility mode in WordPress jQuery:
/* Regular jQuery */ $('.hideable').on('click', function() { $(this).hide(); }) /* Compatibility Mode */ jQuery('.hideable').on('click', function() { jQuery(this).hide(); })
This article is fantastic and tells you pretty much everything you need to know about how to correctly load jQuery scripts in WordPress. Also remember that WordPress bundles the jQuery library already, so you don’t need to embed that anywhere.
TLDR here’s the common way to save keystrokes:
(function($) { $('.hideable').on('click', function() { $(this).hide(); }) })( jQuery );
It tells the script to treat any $
sign as jQuery
string.
a better question is why tf did jQuery bake this into their codebase lol
@Stephanie method is most common.
Friends, the time has come for us to ask for your financial support. After 5+ years of (growing) expenses, and taking time away from consulting and services, we must start generating donations in order to continue this level of rapid project development. Please consider donating, so that we can keep SlickStack free and open source. Thank you! 🙏 😍
We champion core values like free speech, transparency, and portability, and welcome anyone else who does too.
Here is a non-exhaustive list of plugins, themes, and other services that we recommend checking out.
Every stack script and server deployment platform is a bit different, so check to see how SlickStack compares.
Subscribe to our free newsletter to receive occassional updates, we respect your privacy and do not sell your information.
Here’s some of the incredible performance features you can expect after launching your SlickStack cloud VPS.
If you are wondering what specific problems SlickStack can help solve, browse some of the solutions below.
In lieu of donations, please show your support by mentioning SlickStack on your blog or write a review. Thank you!