Moving Javascript from footer to header

Plugin class is using action-hook for wp_footer in it's init function to assing script to footer. In that callable it does do two things:

  1. Registers the script (with in_footer argument true)
  2. Enqueues the script

This is somewhat bad design since registering and enqueueing is done in the same function. Also the fact that the script is registered quite late in wp_footer and with in_footer arg so why register it in wp_footer hook.

And now, this script should be rendered in header before any other script but how? I can remove it wp_denqueue_script in wp_footer hook but cannot reassign it to wp_head. Sounds super simple but couldn't find any working solutions.

There's also some class related methods that are used to create resource url for the script and therefore I should somehow be able to call that class while hooking to plugins_loaded or similar.

Topic footer wp-register-script headers wp-enqueue-script hooks Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.