• I have a plugin that uses jQuery, when activated, it breaks my template.
    The plugin does not work unless I comment out the following in the footer.php
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

    When I comment this jquery out the template breaks. When it’s not commented out, the template is fine, but the plugin does not work.

    This is in my functions.php

    add_filter( 'wp_enqueue_scripts', 'change_default_jquery', PHP_INT_MAX );
    
    function change_default_jquery( ){
        //wp_dequeue_script( 'jquery');
        //wp_deregister_script( 'jquery');
    }

    The main problem is that there are two jQuery files with the same version loaded. I can’t find the call to jquery.js?ver1.11.1 that shows up in the header. I want to add script, and need to use wp_register_script() and wp_enqueue_script() functions.

    I found a solution, but i don’t understand how it works.

    function wptuts_scripts_with_jquery()
    {
        // create array of all scripts
        $scripts=array('custom-script'=>'/js/custom-script.js',
                      'custom-script1'=>'/js/custom-script1.js',
                      'custom-script2'=>'/js/custom-script2.js');
        foreach($scripts as $key=>$sc)
        {
           wp_register_script( $key, get_template_directory_uri() . $sc, array('jquery') );
           wp_enqueue_script( $key );
        }
    }
    add_action( 'wp_enqueue_scripts', 'wptuts_scripts_with_jquery' );

    How do I solve this problem?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How do I use wp_register_script() and wp_enqueue_script() functions’ is closed to new replies.