Only enqueue scripts when needed

The scripts should only be enqueued when they are needed. I'm not sure if this commit takes care of that, there may be more times that the scripts should be enqueued. Enqueueing the scripts unconditionally increases the sites load time unnecessarily. The only issue this could possibly cause is with old, poorly written themes that do not call wp_footer.