Reputation: 609
Have used the same code before and it worked so it's not the code thats the problem. I have only changed the class names in the current code but it doesn't load the jQuery or CSS. This is how I call the scripts.
add_action( 'wp_enqueue_scripts', 'scripts' );
function scripts() {
wp_enqueue_style( 'style', plugins_url('css/style.css', __FILE__) );
wp_enqueue_script( 'style' );
wp_register_script( 'jquery', plugins_url('js/jquery.js',__FILE__ ), array( 'jquery' ));
wp_enqueue_script('jquery');
}
Like I said, have used the exact same method before but this time it doesn't work. Don't know what to do. Thanks!
Upvotes: 0
Views: 553
Reputation: 2258
Final Update: figure out that the plugin dir has space between the words,, removed the space and the plugin works :)
function scripts() {
wp_register_style( 'style', plugins_url('css/style.css', __FILE__) );
wp_enqueue_style( 'style' );
wp_register_script( 'jquery', plugins_url('js/jquery.js',__FILE__ ), array( 'jquery' ));
wp_enqueue_script('jquery');
}
Updated code
V2
function scripts() {
if ( ! defined( 'MyPLUGIN_URL' ) )
define( 'MyPLUGIN_URL', plugin_dir_url( __FILE__ ) );
wp_register_style( 'style', MyPLUGIN_URL .'css/style.css');
wp_enqueue_style( 'style' );
wp_register_script( 'jquery', MyPLUGIN_URL .'js/jquery.js');
wp_enqueue_script('jquery');
}
Upvotes: 1
Reputation: 2479
function scripts_func()
{
//----------------------------------------------
// Include css file
//----------------------------------------------
wp_register_style( 'style', plugin_dir_url(__FILE__).'css/style.css', '', '1.0', 'all' );
wp_enqueue_style('style');
//----------------------------------------------
// Include javascript file
//----------------------------------------------
wp_enqueue_script( 'my-js', plugin_dir_url(__FILE__).'assets/myjs.js', array('jquery'), '1.0', false );
}add_action('wp_enqueue_scripts','scripts_func');
Upvotes: 3