0

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);
    }
3
  • 2
    Callbacks are without () Feb 13, 2022 at 9:37
  • new to plugin development, could you please tell me where is the callbacks here?
    – Ammar Awan
    Feb 13, 2022 at 9:39
  • You can check the wordpress documentation about add_action to understand how to work with them Feb 13, 2022 at 9:48

1 Answer 1

2

The 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:

Your Answer

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

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