Two Reasons Why to use Builtin scripts from WordPress
There are two main reasons why using the pre-registered scripts is beneficial. First, this method will help to prevent jQuery conflicts. Second, it is a lot easier to use dependencies. Here is a list of all default scripts included and registered by WordPress. First lets look at an example to help prevent jQuery conflicts: if your plugin uses jQuery 1.9.2 and WordPress uses jQuery 1.11 then some features, like the drag and drop, might not work. So instead of doing this: Continue reading “Include Builtin scripts from WordPress using wp_enqueue_script()”
<link rel="stylesheet" type="text/css" href="<?php echo $your_plugins_url; ?>css/your_css_file.css" />
While technically it is possible to include files using HTML script and link tags on a standalone site, they are not best practice on a WordPress site. The main benefits of using WordPress’s core functions instead of generic HTML are:
- Files are included to the generated page at the right time according to the script dependencies.
- Files will only be included if it has not been already included and if all the dependencies have been registered.
- Script localization is very easy, just call wp_localize_script() on your included files. Check out Script Localization with JQuery in WordPress for more information.