• Hi there,

    I want to start using the javascripts that are included with WordPress, but I am having a hard time trying to use them. Particularly I would like to use Jquery.

    I edited my header.php and added the following line:

    <?php wp_enqueue_script(‘jquery’); ?>

    as per the reference in: http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    But this doesn’t seem to work. I was wondering if THEME EDITORS could make use of the JS files that come with WordPress, or if we need to download and install scripts separately.

    The reason why I would like to use the built-in scripts is that it would be easier to maintain (/me thinks).

    Thanks for the help

    Cheers,
    P.

Viewing 1 replies (of 1 total)
  • Too late when it gets to that stage. You’re better off adding the following to your theme’s functions.php file:

    add_action( 'wp_print_scripts', 'xyztheme_add_javascript' );
    function xyztheme_add_javascript( ) {
        wp_enqueue_script( 'jquery-ui-tabs', 'js/ui.tabs.js', array( 'jquery' ) );
    }

    This will force wp_print_scripts to include jquery as well as the tabs plugin before it outputs the rest of the headers. This seems to be the only action hook that works reliably with wp_enqueue_script.

    And it makes a lot of sense to use it; my plugin loads the WordPress versions of these script files on 2.5.1, instead of the tab code I ship with the plugin… that helps avoid conflicts and duplicate code.

Viewing 1 replies (of 1 total)

The topic ‘wp_enqueue_script – how do I use it?’ is closed to new replies.