i use a plugin that containing this code and i want to change js location to be located in my template directory instead of plugin without editing the plugin files

class jqueryTimelinrLoad  {

  public function registerScripts()

    {

        if (!wp_script_is( 'jquery', 'registered' )) wp_register_script( 'jquery' );



        wp_deregister_script('jquery.timelinr');

        wp_register_script('jquery.timelinr', JQTL_BASE_URL . '/assets/js/jquery.timelinr-1.0.js', array( 'jquery' ));

    }
     public function loadScripts() {

            if (!is_admin()) {

                if (!wp_script_is( 'jquery', 'queue' )) wp_enqueue_script( 'jquery' );



                wp_enqueue_script('jquery.timelinr', JQTL_BASE_URL . '/assets/js/jquery.timelinr-1.0.js', array( 'jquery' ));

            }

        }
}

i try this and it add the new link but old link also still

function drw_timeline_js () {

        $result = $GLOBALS["jqueryTimelinrLoad"]->loadScripts();


        wp_dequeue_script('jquery.timelinr');
        wp_deregister_script( 'jquery.timelinr');


        wp_enqueue_script('jquery.timelinr2', get_template_directory_uri() . '/js/jquery.timelinr-1.0.js', array( 'jquery' ));

        return $result;
    }
add_action('init', 'drw_timeline_js', 1);

2 Answers
2

Scripts should be enqueued on wp_enqueue_scripts action hook, which runs after init action. So dequeuing on init won’t work because sripts are not enqueued yet. Before enqueued scripts are printed, wp_print_scripts action is triggered so you can dequeue or unregister scripts safely at this moment:

add_action( 'wp_print_scripts', 'drw_timelinr_dequeue' );
function drw_timelinr_dequeue () {

     wp_dequeue_script('jquery.timelinr');

}

add_action('wp_enqueue_scripts', 'drw_timeline_js');
function drw_timeline_js () {

    wp_enqueue_script('jquery.timelinr2', get_template_directory_uri() . '/js/jquery.timelinr-1.0.js', array( 'jquery' ));


}

Leave a Reply

Your email address will not be published. Required fields are marked *