So I have the action for loading my scripts in my plugin as so.
add_action( 'init', array( $this, 'loadAssets' ) );
And the corresponding function set as so:
public function loadAssets() {
// add stylesheet to all pages
wp_enqueue_style(
'styles', // handle
plugins_url( 'styles/main.css', __FILE__ ), // src for js
array(),
WP_DEBUG ? time() : $this->version // version, null removes version, false uses wordpress version
);
wp_register_script( 'jquery.ezmark.min', // handle
plugins_url( 'js/jquery.ezmark.min.js', __FILE__ ), // src for js
array( 'jquery' ), // dependancies
WP_DEBUG ? null : $this->version, // version, null removes version, false uses wordpress version
true
);
}
Now the main.css load in perfectly fine but no matter what I do the Javascript files do not load at all.
They where working perfectly fine yesterday and now when I loaded the site they stopped working.
Any help would be greatly appreciated.
Change this ,
add_action( 'init', array( $this, 'loadAssets' ) );
to this,
add_action( 'wp_enqueue_scripts', array( $this, 'loadAssets' ) );
To include CSS and jQuery in your plugin is easy, try this:
// register jquery and style on initialization
add_action('init', 'register_script');
function register_script() {
wp_register_script( 'custom_jquery', plugins_url('/js/custom-jquery.js', __FILE__), array('jquery'), '2.5.1' );
wp_register_style( 'new_style', plugins_url('/css/new-style.css', __FILE__), false, '1.0.0', 'all');
}
// use the registered jquery and style above
add_action('wp_enqueue_scripts', 'enqueue_style');
function enqueue_style(){
wp_enqueue_script('custom_jquery');
wp_enqueue_style( 'new_style' );
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.