WordPress has been in our lives for more than 16 years, but the method of adding scripts to themes and plug-ins is still a mystery for many developers. In this report, we finally quelled the chaos. Because it is one of the most commonly used JavaScript libraries, today we will discuss how to add simple jQuery scripts to WordPress Themes or plug-ins. But first, it’s important to understand jQuery’s compatibility mode before you start attaching scripts to… JQuery’s compatibility mode information WordPress. The
As you know, WordPress preloads jQuery that you can use with your code. WordPress’ jQuery also provides a mechanism \
Good news? With just a few changes, you can go back to using our cute little dollar symbol again. If btw and jQuery are used for the first time, the $symbol is the alias of jquery() and the alias of the function. The default structure is $(selector). Action() Dollar sign defines jQuery. (selected by) query or find HTML elements Finally, \
1. the first way to bypass the jQuery implicit mode and enter the compatibility mode is to use code implicitly. For example, if you load a script into a footnote, you can use anonymous functions to grab the code. JQuery will be mapped to $. As shown in the following figure: to add a script to the 9463033d31b54e8c0bd3ab9d3770329 header of the loading summary (if possible, it must be avoided, as described in detail below), you can use the document preparation function to grab all the contents, and then pass $. Load summary 626f5d6b73425c68321041126b7e262d2. Another easy way to avoid switching to \
In this case: $j instead of the default $. Just declare it at the top of the script. Var $j = jquery Noconflict(); Now that we know how to write effective jQuery code for WordPress, we add it to the site. How to add a jQuery script to WordPress one of the easiest ways to add a jQuery script to WordPress is to use a process called \
Handle all dependencies in this way (benefit from WP!). Functions when using themes. You can use the wp\u enqueue\u script() function in your PHP file. Including: Load summary a079c7cd9663a1a789b0a17fca8fb458 this function uses five arguments$ Handle – a unique handle that can be used to reference a script$ SRC – the location of the script file$ DEPs – specifies an array of dependencies$ Ver version number of the script