I have two sites which I've copied a plugin from the first site and then altered the plugin and changed the name of plugins directoy and class name.

Like from:


In the root of this plugin I have file called old_xplugin.php and class name equiavivalent: class old_xplugin


new_xplugin (now with modifications of the old xplugin) In the root of this plugin I now a have file called new_xplugin.php and class name equiavivalent: class new_xplugin

Everything works until I change the name of the folder. (I can change name of the plugin, and the class name without problem).

But when I change the name of the folder I get jQuery reference eror: not defined. Why isn't jQuery loaded when change of the plugins folder?

This is the structure of the plugin file(s):

main plugin file (new_xplugin.php). These things are not changed after copying the plugin.

public function __construct() {                        
    //Iniate jquery and css
    add_action( 'wp_enqueue_scripts', array($this, 'js_css' ) );                             

public function js_css() {                       
        plugins_url( '/js/wtf.js' , __FILE__) 


jQuery(function ($) {    //Wordpress says: jQuery reference error: undefined.

2 Answers 2


No idea why the change of folder name makes a difference, but you should add jquery as dependency in your enqueue

        plugins_url( '/js/wtf.js' , __FILE__),
  • Sorry but it did not work. Same error. Feb 11, 2016 at 13:43
  • 1
    you should check if jquery is being loaded Feb 11, 2016 at 13:44

Thanks to @Mark Kaplun that spotted the actual issue. jQuery did not load before wp_enque_script was executed. So I hooked the function js_css() into init like this:

add_action( 'init', array( $this, 'js_css' ) );

and that solved the problem! :-)

(Very strange that this even worked on site1 though)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.