I'm trying to create a WordPress plugin, and I would like to have jQuery UI Tabs in one of my settings pages.
I already have the scripting code set:
wp_enqueue_script('jquery'); // Enque jQuery
wp_enqueue_script('jquery-ui-core'); // Enque jQuery UI Core
wp_enqueue_script('jquery-ui-tabs'); // Enque jQuery UI Tabs
...and I have created the HTML and JavaScript too. Until here all are fine.
The question is:
The WordPress platform comes with some scripts already pre-installed like the one I have enqueue above. My script runs fine with the tabs, but it is not styled! So what I'm trying to ask, does the WordPress platform come with jQuery UI Theme pre-installed? ...and if so, how do I enqueue the style into my plugin?
Sounds more like you have an issue with finding an available styling within WordPress for the jquery-ui theme.
To answer your question. No, WordPress has no useful styles available within the platform itself. The only available css is in \wp-includes\jquery-ui-dialog.css, and that alone isn't very useful.
I also had the same issue, and I found two options. Either store it in a CSS folder and load it from there, or load it via URL (Google APIs). For JQuery UI I decided to rely on Google's CDA and added a way to utilize the 'Theme Roller'. Storing that amount of css code seems un-nessecary to begin with, and its too bad WordPress doesn't provide any styling support like they do with the jquery-ui scripts.
However, WP does offer scripts, which will keep the CSS up to date with $wp_scripts->registered['jquery-ui-core']->ver
. You can either access it with wp_scripts();
OR global $wp_scripts;
.
Static-theme
$wp_scripts = wp_scripts();
wp_enqueue_style(
'plugin_name-admin-ui-css',
'http://ajax.googleapis.com/ajax/libs/jqueryui/'
. $wp_scripts->registered['jquery-ui-core']->ver
. '/themes/smoothness/jquery-ui.css',
false,
PLUGIN_VERSION,
false
);
OR Dynamic-theme
$wp_scripts = wp_scripts();
wp_enqueue_style(
'plugin_name-admin-ui-css',
'http://ajax.googleapis.com/ajax/libs/jqueryui/'
. $wp_scripts->registered['jquery-ui-core']->ver
. '/themes/' . $pluginOptions['jquery_ui_theme']
. '/jquery-ui.css',
false,
PLUGIN_VERSION,
false
);
And an example of locally storing it
wp_enqueue_style(
'plugin_name-admin-ui-css',
plugins_url()
. '/plugin-folder-name/includes/css/jquery-ui-theme-name.css',
false,
PLUGIN_VERSION,
false
);