TURN enqueue ON/OFF

8 views
Skip to first unread message

jean page

unread,
Apr 27, 2012, 11:31:28 AM4/27/12
to WordPress Austin
I was wondering why I don't see anyway to use the JS libraries that
already come packaged in a WP install? All that stuff which is used on
the admin side. Shouldn't there be a way to just reference and use any
of those scripts on the public side of your Wordpress UI.

Thanks,
Jean

Brandtley McMinn

unread,
Apr 27, 2012, 8:30:04 PM4/27/12
to wordpres...@googlegroups.com
Hey Jean,

You can request any one of the various libraries WordPress comes pre-packaged with using the wp_enqueue_script function in your theme or plugins' functions.php file:

http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Default_scripts_included_with_WordPress

This section of the codex outlines the various libraries you can utilize and all you have to do is use the corresponding handle as an argument in the function. I would write a function that handles loading of all my frontend scripts and hook into 'wp_enqueue_scripts' to load them on the frontend. A basic implementation could look something like this:

<?php

  // Add necessary JS scripts to frontend
  add_action('wp_enqueue_scripts', 'MYTHEME_frontend_js_scripts');

  function MYTHEME_frontend_js_scripts() {
    wp_enqueue_script('jquery');
    wp_enqueue_script('jquery-ui-core', false, array('jquery'));
    wp_enqueue_script('jquery-ui-mouse', false , array('jquery'));
    wp_enqueue_script('thickbox');
    wp_enqueue_script('jquery-hotkeys', false , array('jquery'));
  }

?>

The same could be done for a plugin or theme requiring certain libraries on the admin side by hooking into the 'admin_enqueue_scripts' action.

Hope this helps,

--
Brandtley McMinn - Owner/Creative Director
http://giggleboxstudios.net
c. 512.406.1666
@brandtleymcminn


Friday, April 27, 2012 10:31 AM
Reply all
Reply to author
Forward
0 new messages