How to Use & Work with jQuery UI in Wordpress
Last updated
Was this helpful?
Last updated
Was this helpful?
WordPress is the powerful CMS of PHP language. There are several features which makes flexibility to users to work and control the flow of application. WordPress have 10000+ available plugins at wordpress repository which manages wordpress for every functionality.
jQuery UI is a set of plugins which creates amazing effects, themes, widgets built in jQuery libraries.
jQuery UI are the set of plugin files which creates interactive web applications.
It is Open source means freely available to use.
Due to jquery plugins support, it creates a powerful theme mechanism.
Easy to use and simple implementation in any applications.
It has great level browser support extensions.
Great collections of widget plugins.
jQuery have multiple libraries for different different tasks. It provides for jquery interactions like Draggable, Droppable, Resizable, etc.
It also contains several pretty useful widgets like Accordion, Autocomplete, Button etc.
There is very simple way to use jQuery UI in application. First we need an application like in HTML, in PHP any of the framework or language etc. Download basic files of jquery & jquery ui. Here, basic files refers to using jQuery main file and jquery ui css and jquery ui js.
Main jquery file can BE downloaded from several CDN links. Download any of like minified or simple.
WordPress is powerful system which maintains everything inside it. jQuery UI is also available as a default set of features. Many of the wordpress developers donât have the idea to use them. Instead if they need, they used to bind extra plugin files from outside and work.
So, jQuery UI is default support feature of wordpress. As in the previous topic we have seen that when we want to use jquery ui features we need few files in application. In wordpress where we should find those files â interesting.
We can see the default available jquery ui files in wordpress. No need to download any extra plugin file to use jquery-ui features. Inside this folder we can find all widget plugin files and interactive files.
As already discussed, we need to these files â
jQuery Main file
jQuery UI CSS
jQuery UI Plugin file
When we download theme from this link, we get jquery ui files with css files. For our work, we need only CSS because jquery ui js already available inside wordpress setup.
Letâs say we are going to create a plugin in which we will use jquery UI features (like widgets).
Create WordPress Project URL
Load CSS, main jQuery file, jQuery ui js file
wp_enqueue_style â This function will registers css file of jquery-ui. Keep in mind this CSS file we have download already from above steps. We have moved that downloaded CSS into any created plugin. JQUERY_UI_WP_URL is a constant defined above.
wp_enqueue_script â This function is used to registers javascript, jquery plugin files.
wp_enqueue_script(âjqueryâ); â This line loads jquery main file from wordpress setup. jquery.js file you can find at /wp-includes/js/jquery/jquery.js.
wp_enqueue_script(âjquery-ui-accordionâ); â It loads jquery ui accordion js file. This files loads from /wp-includes/js/jquery/ui/accordion.min.js
We are going to create a basic plugin in wordprss. In this plugin we will use jquery ui widget â accordion. Step by step about each functions we will see. Additionally, we will cover about plugin development step wise as well.
Create a Plugin Folder at path â /wp-content/plugins/my-jquery-widget
Create a plugin file namely inside that folder as â wp-my-jquery-widget.php
Step by step we append code into plugin file.
Registering Menu & a submenu on plugin activation
wp_jquery_ui_callback_fn is a callback function which runs when we click on plugin menu or submenu. Because same callback function is used for both.
Inside this callback function we used PHP buffer concept to load view file. So, we need to create view file with the name accordion.php in /views folder.
Adding Html code to view file â
Letâs see the output what we have created so far
Now, we need to add library files for jquery UI for accordion widget â
Successfully, we have registered needed jquery ui files, also we have attached the css for ui theme.
Here, we have attached a custom script file âcustom-scriptâ in which we will add accordion method to use it.
When we reload the plugin backend at wordpress admin panel we will get output as â
Finally, we have implemented the concept of jquery ui in wordpress in a very easy way. No need to any extra js plugin files.
As you have seen so far, inside this â we need some basic files to add any widget to plugin. For example â we need jquery js plugin file for accordion, main file and a ui theme css file. Thatâs it.
Pragmatically, we used these lines for accordion â
For other widgets in jQuery UI, we need their respective libraries as â
JQuery UI Autocomplete â wp_enqueue_script(âjquery-ui-autocompleteâ);
JQuery UI Datepicker â wp_enqueue_script(âjquery-ui-datepickerâ);
JQuery UI Dialog â wp_enqueue_script(âjquery-ui-dialogâ);
You should find something when you go to above link â
So, to use jQuery UI widgets, effects â We need to use above core files. In wordpress setup by default jQuery UI js, jquery main file we can find easily. But for CSS we need to download from itâs official.
To get the complete code here we have the github link to download the source code. .
You can find complete information about available plugins here. Redirect to .