I am trying to include my own scripts in a child theme I set up.
I have the following in functions.php:
function custom_scripts() {
wp_enqueue_script('custom_js', get_stylesheet_directory_uri() . 'custom_js.js', array('jquery'), '1.0.0', false );
}
add_action( 'wp_enqueue_scripts', 'child_theme_configurator_css', 'custom_scripts', 10 );
but for some reason it isn't showing up in the scripts area within the page source.
I tried placing the custom_js.js file in the following paths:
/custom_js.js (root)
/wp-includes/js/custom_js.js
/wp-content/themes/oceanwp-child/custom_js.js
but haven't had any luck. Any help would be appreciated.
I am trying to include my own scripts in a child theme I set up.
I have the following in functions.php:
function custom_scripts() {
wp_enqueue_script('custom_js', get_stylesheet_directory_uri() . 'custom_js.js', array('jquery'), '1.0.0', false );
}
add_action( 'wp_enqueue_scripts', 'child_theme_configurator_css', 'custom_scripts', 10 );
but for some reason it isn't showing up in the scripts area within the page source.
I tried placing the custom_js.js file in the following paths:
/custom_js.js (root)
/wp-includes/js/custom_js.js
/wp-content/themes/oceanwp-child/custom_js.js
but haven't had any luck. Any help would be appreciated.
Share Improve this question edited Feb 21, 2020 at 19:50 butlerblog 5,1213 gold badges28 silver badges44 bronze badges asked Feb 21, 2020 at 19:06 elpretentioelpretentio 33 bronze badges1 Answer
Reset to default 0Your add_action
has incorrect parameters. Use this code
add_action( 'wp_enqueue_scripts', 'custom_scripts', 10 );
Also, you must prefix filename with /
, so correct function code is
function custom_scripts() {
wp_enqueue_script('custom_js', get_stylesheet_directory_uri() . '/custom_js.js', array('jquery'), '1.0.0', false );
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744725632a4590160.html
评论列表(0条)