Making my own custom plugin and using add_action several times without a problem with one exception. Currently function below are located in functions.php in the appropriate themes folder.

function enqueue_custom_scripts() {
   error_log('enqueue_custom_scripts function is executing'); // In enqueue_custom_scripts
   wp_enqueue_script('custom-ajax-script', get_stylesheet_directory_uri() . '/js/custom-ajax-script.js', array('jquery'), null, true);

   wp_localize_script('custom-ajax-script', 'ajax_object', array(
       'ajax_url' => admin_url('admin-ajax.php'),
       'nonce'    => wp_create_nonce('my-custom-ajax-nonce'),
add_action('wp_enqueue_scripts', 'enqueue_custom_scripts');

I have tried several version of this, in several files including plugin main file. Note: Not even the error_log trigger. The odd thing is that it works if user not logged in. Probably some stupid mistake I made so help is appreciated.

1 Answer 1


As noted in the documentation, the wp_enqueue_scripts hook (emphasis mine):

...is the proper hook to use when enqueuing scripts and styles that are meant to appear on the front end.

If you want to enqueue scripts in the admin, you need to use admin_enqueue_scripts.

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.