How to correctly include jQuery-UI effects on WordPress on your existing Theme without much compromise on Page Loading Speed? It is made easy with our Guide. Those who are new, can read our previous article What is jQuery with Example. jQuery-UI effects on WordPress can be done by using some Plugins or using wp enqueue script. Here are some important articles which are directly or indirectly related or can be used with this guide on how to correctly include jQuery-UI effects on WordPress :
- Handy Guide for WP Enqueue Script For WordPress Themes
- Eliminate Render-blocking Javascript and CSS WordPress
- Transient and WordPress
- Why My WordPress is So Slow?
How to correctly include jQuery-UI effects on WordPress : Introduction
jQuery UI is an extension of free JavaScript library jQuery and provides solutions to design and add functionality of the user interface. jQuery UI was released in September 2007, announced by John Resig on jquery.com. The latest release, 1.10.1, requires jQuery 1.6 or later. jQuery UI uses Grunt js.
Interactions :
---
- Draggable and Droppable – allows Drag and Drop
- Resizable – allows the user to magnify an element in and out
- Selectable – Advanced functionality for marking elements
- Sortable – adds functionality for sorting of similar items
Effects :
The underlying jQuery framework already offers some effects which jQuery UI extends :
- Color animation
- Animation of a class – animates the change of a style sheet class
- Blend effects
- Widgets
Widgets are pre-programmed solutions for Web developers who want to use common elements of user interfaces:
- Autocomplete
- Provides a function for auto-completion of text fields, also alaviable via Ajax
Button - Provides an interface for providing common buttons designs
- DatePicker
- Provides a menu to select a date ready dialogue
- Offers the possibility of adding a dialog box
- Provides an interface for displaying a progress bar
- Provides a slider
- Tabs
- Gives the developer the option tabs represent
- Accordion
- Represents a type of folding with certain elements for automatically extend and retract
Official website and repo of sourcecode :
1 | http://jqueryui.com/ |
1 | #repository |
1 | https://github.com/jquery/jquery-ui |
1 | #Demo |
1 | http://jqueryui.com/demos/ |
How to correctly include jQuery-UI effects on WordPress : Options to include
There are Plugins for WordPress like –
1 | http://wordpress.org/plugins/jquery-ui-widgets/ |
However, we will suggest to use methods described in the guide WP Enqueue Script For WordPress Themes. These method will not throw/increase the bad sort of warning – Eliminate Render-blocking Javascript in Google Page Loading Speed test. You must deliver from a CDN for quicker deliver. The fact is, all of these scripts are already registered to print in the footer. You can see wp-includes/script-loader.php for details. When you try to register the scripts again WordPress doesn’t change that :
1 2 3 | wp_enqueue_script( "myUi","https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.8/jquery-ui.min.js" ); |
The workaround would be to register a new script for wp_head with those scripts as dependencies (the third parameter of wp_enqueue_script()). Do not register the scripts in another order before WordPress does it! This will affect wp-admin and probably other pages too.
So, the things goes like this :
function add_scripts(){
wp_enqueue_script( ‘jquery-ui-autocomplete’ );
}
add_action(‘wp_enqueue_scripts’, ‘add_scripts’);
Add these in header with some Header Footer sort of Plugin, most theme has some functions :
1 2 | <script type='text/javascript' src='//source/wordpress/wp-includes/js/jquery/jquery.js?ver=1.9.1'></script> <script type='text/javascript' src='http://localhost/wordpress/wp-includes/js/jquery/jquery-migrate.js?ver=1.1.1'></script> |
And to footer :
1 2 3 4 5 | <script type='text/javascript' src='//source/wordpress/wp-includes/js/jquery/ui/jquery.ui.core.min.js?ver=1.10.2'></script> <script type='text/javascript' src='//source/wordpress/wp-includes/js/jquery/ui/jquery.ui.widget.min.js?ver=1.10.2'></script> <script type='text/javascript' src='//source/wordpress/wp-includes/js/jquery/ui/jquery.ui.position.min.js?ver=1.10.2'></script> <script type='text/javascript' src='//source/wordpress/wp-includes/js/jquery/ui/jquery.ui.menu.min.js?ver=1.10.2'></script> <script type='text/javascript' src='//source/wordpress/wp-includes/js/jquery/ui/jquery.ui.autocomplete.min.js?ver=1.10.2'></script> |
In case, you do not want all to load :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | function my_enqueue_scripts_method() { wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core', false, array('jquery'), false, false); wp_enqueue_script('jquery-ui-widget', false, array('jquery'), false, false); wp_enqueue_script('jquery-ui-mouse', false, array('jquery'), false, false); wp_enqueue_script('jquery-ui-accordion', false, array('jquery'), false, false); wp_enqueue_script('jquery-ui-slider', false, array('jquery'), false, false); wp_enqueue_script('jquery-ui-tabs', false, array('jquery'), false, false); wp_enqueue_script('jquery-ui-sortable', false, array('jquery'), false, false); wp_enqueue_script('jquery-ui-draggable', false, array('jquery'), false, false); wp_enqueue_script('jquery-ui-droppable', false, array('jquery'), false, false); wp_enqueue_script('jquery-ui-selectable', false, array('jquery'), false, false); //wp_enqueue_script('jquery-ui-datepicker', false, array('jquery'), false, false); wp_enqueue_script('jquery-ui-resizable', false, array('jquery'), false, false); wp_enqueue_script('jquery-ui-dialog', false, array('jquery'), false, false); //wp_enqueue_script('jquery-ui-button', false, array('jquery'), false, false); } add_action('wp_enqueue_scripts', 'my_enqueue_scripts_method', 1); |