简体   繁体   中英

WordPress difficulty enqueueing accordion script

I'm a newbie to "WordPress and I'm having problems enqueueing a script. my script is called accordion (It's the one from http://www.w3schools.com/howto/howto_js_accordion.asp )
the file is called accordion.js I've placed it in the twentyseventeen/assets/js folder

and I tried to enqueue it by typing this(below) into my functions.php file.

function accordion() {  wp_enqueue_style( 'theme-style', get_stylesheet_uri(), array( 'reset' ) );  wp_enqueue_style( 'reset',

get_stylesheet_directory_uri() . '/reset.css' ) );

wp_enqueue_script( 'accordion', get_stylesheet_directory_uri() . '/accordion.js', array( 'jquery' ) );

wp_enqueue_script( 'theme-scripts', get_stylesheet_directory_uri() . '/website-scripts.js', array( 'accordion', 'jquery' ), '1.0', true ); }    

This doesn't work, so I did something wrong (and silly), but I don't know what.

Could someone tell me what I did wrong and maybe point me in the right direction?

Marcel

You mentioned that the .js script is in the assets/js folder of the theme, but it looks like you are referencing it in the root of the theme folder:

wp_enqueue_script( 'accordion', get_stylesheet_directory_uri() . '/accordion.js', array( 'jquery' ) );

Instead of:

wp_enqueue_script( 'accordion', get_stylesheet_directory_uri() . '/assets/js/accordion.js', array( 'jquery' ) );

Check this same thing for your other scripts & stylesheets in the function.

Also, where are you actually calling the accordian() function? Make sure you are actually calling it from somewhere in the head of the template.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM