javascript - Setting wp_enqueue_script correctly

I am trying to include my own scripts in a child theme I set up.I have the following in functions.php:function custom_sc

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 badges
Add a comment  | 

1 Answer 1

Reset to default 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 );
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744725632a4590160.html

相关推荐

  • javascript - Setting wp_enqueue_script correctly

    I am trying to include my own scripts in a child theme I set up.I have the following in functions.php:function custom_sc

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信