Answer the question
In order to leave comments, you need to log in
How to include styles and scripts in a wordpress child theme?
Styles and scripts are not included in wordpress child theme
add_action( 'wp_enqueue_script', 'my_scripts_slider');
function my_scripts_slider() {
wp_enqueue_script('chifslider1', get_stylesheet_directory_uri() . '/chifslider/chief-slider.dev.js');
wp_enqueue_script('chifslider2', get_stylesheet_directory_uri() . '/chifslider/chief-int.js');
};
wp_enqueue_script('chifslider1', get_stylesheet_directory_uri() . '/chifslider/chief-slider.dev.js');
then connect, and a message is displayedNotice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. This notice was triggered by the chifslider1 handle. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.) in C:\xampp\htdocs\wordpress\wp-includes\functions.php on line 5535
Answer the question
In order to leave comments, you need to log in
I already figured it out - there was a typo in several articles, apparently they torn each other. The code from the English version of the codex works without errors.
The hook is called wp_enqueue_scripts
, and not wp_enqueue_script
To connect files, there is a great function get_theme_file_uri()
that checks for the existence of a file before connecting, it's quite convenient
In the file version, you can specify the time of the last modification, so that when it changes, the browser updates it in its cache withfilemtime()
add_action( 'wp_enqueue_scripts', 'my_scripts_slider' );
function my_scripts_slider() {
wp_enqueue_script( 'chifslider1', get_theme_file_uri( 'chifslider/chief-slider.dev.js' ), array(), filemtime( get_theme_file_path( '/chifslider/chief-slider.dev.js' ) ) );
wp_enqueue_script( 'chifslider2', get_theme_file_uri( 'chifslider/chief-int.js' ), array(), filemtime( get_theme_file_path( '/chifslider/chief-int.js' ) ) );
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question