最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Setting wp_enqueue_script correctly

programmeradmin1浏览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.

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 );
}
发布评论

评论列表(0)

  1. 暂无评论