0

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.

1 Answer 1

0

Your 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 );
}
2
  • Ok, great. Thank you. And may I ask if that is the correct path? The custom_js.js file is currently located in /wp-content/themes/oceanwp-child/custom_js.js and doesn't seem to be having any effect on the page when it loads. Although I do now see it in the page source. Thanks Feb 21, 2020 at 19:28
  • See updated answer. Feb 21, 2020 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.