admin管理员组文章数量:1205753
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'skfans_wp_enqueue_script()' not found or invalid function name in C:\xampp\htdocs\plugin\wp-includes\class-wp-hook.php on line 306:
add_action('wp_enqueue_scripts','skfans_wp_enqueue_script()');
function skfans_wp_enqueue_script() {
wp_enqueue_style('skfans_dev_plugin', plugin_dir_url(__FILE__)."assets/css/style.css");
wp_enqueue_script('skfans_dev_script',plugin_dir_url(__FILE__)."assets/js/custom.js",true);
}
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'skfans_wp_enqueue_script()' not found or invalid function name in C:\xampp\htdocs\plugin\wp-includes\class-wp-hook.php on line 306:
add_action('wp_enqueue_scripts','skfans_wp_enqueue_script()');
function skfans_wp_enqueue_script() {
wp_enqueue_style('skfans_dev_plugin', plugin_dir_url(__FILE__)."assets/css/style.css");
wp_enqueue_script('skfans_dev_script',plugin_dir_url(__FILE__)."assets/js/custom.js",true);
}
Share
Improve this question
edited Mar 8, 2022 at 14:59
fuxia♦
107k38 gold badges255 silver badges459 bronze badges
asked Feb 13, 2022 at 9:30
Ammar AwanAmmar Awan
1
3
|
1 Answer
Reset to default 2The text in the second parameter is not code to run, it is the name of a function. That is why it does not and cannot work. The warning is PHP telling you that no function with that name exists. Or more specifically that is it an invalid function name.
A function with ()
in its name is not possible. For your code to work you would need a function named skfans_wp_enqueue_script()
but that's impossible because it would mean your function looks like this:
function skfans_wp_enqueue_script()() {
This would generate syntax errors and crash immediately.
To clarify the difference, this is what you believed it meant:
add_action('action/event name', 'run this PHP code inside these quotes when action/event happens');
What it actually means:
add_action('action/event name', 'A thing to call when the action/event happens' );
e.g.
add_action( 'save_post', 'wpdocs_my_save_post' );
function wpdocs_my_save_post() {
// .....
Further reading:
- https://www.php.net/manual/en/language.types.callable.php
- https://developer.wordpress.org/reference/functions/add_action/
本文标签:
版权声明:本文标题:I was adding the custom CSS & JS using hooks and there was this error even I didn't touch the wp-class-hook 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738684825a2106761.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
()
– Buttered_Toast Commented Feb 13, 2022 at 9:37