Support » Developing with WordPress » why am I getting two js alert instead of one per plugin function calls

  • Resolved nancy56


    I have to make jquery connection to wordpress. I have two plugin created and installed to test jquery wordpress workability

    when I run the first_plugin

    am supposed to get only one alert “first plugin working” which corresponds to first_plugin function
    Instead am getting 2 alerts

    eg first plugin working
    second plugin working and vice versa

    first_plugin code

    function first_plugin() {
        // JavaScript
        wp_enqueue_script( 'scriptjs1', plugins_url( '/script1.js', __FILE__ ),array('jquery'));
        // Pass ajax_url to script.js
        //wp_localize_script( 'script-js', 'plugin_ajax_object',
                //array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );


    alert('first plugin working');

    second_plugi code

    function second_plugin() {
        // JavaScript
        wp_enqueue_script( 'scriptjs2', plugins_url( '/script2.js', __FILE__ ),array('jquery'));


    alert('second plugin working');

    My question is this: Is it how this wp_enqueue_scripts() function work by alerting content in another second_plugin into first_plugin and vice versa. Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The wp_enqueue_script function simply adds to a list of scripts that must be output in the page, determining their order by the dependency parameter and the order of execution. But it is a PHP function, and has nothing to do with what the script itself does once the page is loaded. The script itself is calling alert, so it seems to be what you have told it to do.

    One thing though, is the handle of the script. You have used the handle ‘scriptjs1’, but then tried to localize it using ‘script-js’. They must match, or the localize won’t work (the variable won’t be output).

    Thanks alot

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.