Wordpress Jquery

Worldpress Jquery

jQuery definition and how it is used in modern web design. An introduction to using jQuery in WordPress themes and plugins. Learn some tips on how to get the most out of sharing jQuery and WordPress to create a great website.

Use of ' $' instead of ' jQuery' in WordPress

The WordPress comes with its own jQuery libary release (for longevity's sakes, while I'm writing this WordPress it's in 3.2.1). To use jQuery in your WordPress plug-ins and your WordPress topics "The Right Way", you just have to queue the scripts (probably via the functions.php of your topic).

This is a simple example: wp_enqueue_script("jquery"); the trick is that this particular copy of jQuery is in compatible fashion by defaults. This means that the jQuery typically $ link does not work, so it does not collide with other JavaScript scripts that also use the Dollars character, such as MooTools or Prototype.

A lot of plug-in writers and themes designers are conscious of this, and they use jQuery instead of $ to be sure. #some-element ").yaddaYaddaYaddaYaddaYadda(); jQuery("#some-element").yaddaYaddaYaddaYadda(); Here's the thing...riting jQuery a billion time in a scripted makes it more difficult to reread and inflates its magnitude. When loading the skript in the bottom line (which you should do in most cases), you can put the source file in an unknown feature (technically any IIFE), where you hand over jQuery to be displayed on $. // console.log($); })( jQuery ); if you really need to upload the skripts in the top line, you probably still need to use a document-ready feature, so you can just insert $ there.

console.log($); }); Go out and type beautiful looking jQuery!

Embed jQuery in WordPress (The right way)

You can simply jQuery, put it on your web site and from your headers create a hyperlink to it. see your pdf files in the section. First, some plug-ins use and will use the jQuery lib. A lot has been changing with the way WP scripts are loaded since this paper was published.

Nowadays WordPress downloads jQuery for you whenever another scripts needs it. Intelligent uploading will require that you specify jquery as the $deps parameters when you mount your other JavaScript scripts, e.g.: wp_enqueue_script('my-custom-script', get_template_directory_uri().'/js/my-custom-script. js', array('jquery'), null, true); this will declare jQuery as a constraint for my-custom-script, so WordPress will auto upload its own copy of jQuery.

So, when we are declaring our user-defined scripts, we put the $deps argument to array('jquery') and call it a tag. Well, let's say we want to use a jQuery that is different from the one in WordPress. You could just put it in the queue, but then two copies/versions of jQuery would be on the page (yours and WP's).

So, before we queue our own jQuery release, we need to unregister the WP release. js', array(), null, true); add_action('wp_enqueue_scripts','shapeSpace_include_custom_jquery'); here we use wp_deregister_script() to unregister the jQuery from WP before we queue our own release, for example the jQuery jlib, 3.1.1 hosting from Google, 3.1.1. Of course, you will want to modify the $src parameters to adjust the address of the jQuery scripts you want to use.

This is the actual "right way to integrate jQuery into WordPress". An important hint for topic developers: Published topics should use jQuery from WP and not deregister. The other thing is that WordPress already contains a copy of jQuery. This is how you can intelligently (and intentionally) use jQuery in your design.

Most likely your themes already have the wp_head feature, so just make sure you call the wp_enqueue_script feature BEFORE calling it. Now, you are all ready to invoke your own jQuery JavaScript spreadsheet AFTER the wp_head feature. As an example, to protect against the potential conflicts with other library systems in the near term. In order to be extra secure, you can put jQuery into "no conflict" and use another abbreviation for jQuery.

For example, the default "$" may come into contact with the prototype. Below is an example of a secure jQuery JavaScript bit: var $j = jQuery. noConflict(); paddingLeft: "20px&" }, 400); }, 400); } } } }); }); Can you see this jQuery JavaScript bits? 1Editorial note: The Links Nucleus demonstration has been deleted (it was part of an older design).

Auch interessant

Mehr zum Thema