• Resolved tango

    (@tango)


    Hi,

    I’ve a pluigin that needs to load jquery.js plus my own javascript.

    At the moment this is done via a function that prints the <script…> tags using the add_action(‘wp_head’, ‘my_head_function’).

    I’d like to move to the wp_register_script and wp_enqueue_script functions of wordpress in order to deal with themes or other plugins loading the same library, but I do not manage to get it work.

    Can you please point at some working example where a plugin correctly load a js distributed with wordpress and plugin-specific js using such functions?

    Thanks, Sergio

Viewing 1 replies (of 1 total)
  • Thread Starter tango

    (@tango)

    This is what I understood and that works for me:

    in the plugin module, add something like:

    function myplugin_init() {
    if (function_exists(‘wp_enqueue_script’)) {
    // for lirabries part of wordpress
    wp_enqueue_script(‘jquery’);
    // for new libraries
    wp_register_script(‘my_js_lib’, get_bloginfo(‘wpurl’) . ‘/wp-content/plugins/mypling/js/my_js_lib.js’, array(‘dep if any’), ‘version’);
    wp_enqueue_script(‘my_js_lib’);
    }
    }

    add_action(‘init’, ‘myplugin_init’);

Viewing 1 replies (of 1 total)

The topic ‘wp_register_script and wp_enqueue_script’ is closed to new replies.