Topic: js not working in wordpress
Suellyn Specie
asked 10 years ago
ashelighmorehattia
pro answered 9 years ago
This works 100%. The key was to add 'array('jquery'));' to js files in the directory instead of 'array(), '1.1.0', true );'
function theme_enqueue_scripts() {
wp_enqueue_style( 'Font_Awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css' );
wp_enqueue_style( 'Bootstrap_css', get_template_directory_uri() . '/css/bootstrap.min.css' );
wp_enqueue_style( 'MDB', get_template_directory_uri() . '/css/mdb.min.css' );
wp_enqueue_style( 'Style', get_template_directory_uri() . 'https://mdbcdn.b-cdn.net/style.css' );
wp_enqueue_script( 'jQuery', get_template_directory_uri() . '/js/jquery-3.2.1.min.js', array(), '3.2.1', true );
wp_enqueue_script( 'Tether', get_template_directory_uri() . '/js/tether.min.js',array('jquery'));
wp_enqueue_script( 'Popper', get_template_directory_uri() . '/js/popper.min.js', array('jquery'));
wp_enqueue_script( 'Bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'));
wp_enqueue_script( 'MDB', get_template_directory_uri() . '/js/mdb.js', array('jquery'));
wp_enqueue_script('CustomJS', get_template_directory_uri() . '/js/custom-js.js', array('jquery'));
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_scripts' );
espiran commented 9 years ago
ashelighmorehattia thanks a lot, bro! your code for wp_enqueue_script worked for me!
Erick Maeda
answered 10 years ago
Maciej Szuchta
answered 10 years ago
<?php
/**
* Include CSS files
*/
function theme_enqueue_scripts() {
wp_enqueue_style( ‘Font_Awesome’, ‘https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css’ );
wp_enqueue_style( ‘Bootstrap_css’, get_template_directory_uri() . ‘/css/bootstrap.min.css’ );
wp_enqueue_style( ‘MDB’, get_template_directory_uri() . ‘/css/mdb.min.css’ );
wp_enqueue_style( ‘Style’, get_template_directory_uri() . ‘/style.css’ );
wp_enqueue_script( ‘jQuery’, get_template_directory_uri() . ‘/js/jquery-2.2.3.min.js’, array(), false, true );
wp_enqueue_script( ‘Tether’, get_template_directory_uri() . ‘/js/tether.min.js’, array(), false, true );
wp_enqueue_script( ‘Bootstrap’, get_template_directory_uri() . ‘/js/bootstrap.min.js’, array(), false, true );
wp_enqueue_script( ‘MDB’, get_template_directory_uri() . ‘/js/mdb.min.js’, array(), false, true );
}
add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_scripts’ );
?>
Hope that it will help.
Erick Maeda
answered 10 years ago
Suellyn Specie
answered 10 years ago
Maciej Szuchta
answered 10 years ago
Erick Maeda
answered 10 years ago
Suellyn Specie
answered 10 years ago
teawebsite
pro answered 10 years ago
Andre Cordeiro
answered 10 years ago
Pruthul Pradeep A commented 6 years ago
Thanks man! After hours of googling, this finally saved me. Silly me.. forgot this.
Maciej Szuchta
answered 10 years ago
Suellyn Specie
answered 10 years ago
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Free
- Premium support: No
- Technology: General Bootstrap questions
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: No
- Provided link: No