Plugin Activation Causes wp_register errors

The warning is self-explanatory:

Notice: wp_register_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks.

You have to call wp_register_style on the correct hooks:

  • wp_enqueue_scripts for the frontend
  • admin_enqueue_scripts for the backend
  • login_enqueue_scripts for the login page

Calling wp_register_script on any other hook, or no hook at all, is incorrect, and will generate that warning. This is because unless you call it on those 3 hooks, the functions might not work as expected, and your script might not be enqueued or registered. Either because it’s registered too late, or, because it’s registered too early

Also, you can register and enqueue at the same time by using wp_enqueue_script and passing all the parameters. wp_register_script can be useful, but it isn’t always necessary


As for why it appeared in production and not locally, these are PHP warnings, and your local environment may be configured to only show errors, not warnings/notices. I recommend logging everything to an error log and checking that. A plugin such as query monitor can also aid in revealing warnings and notices.