Title: Action wp_enqueue_scripts does not run, if Autoptimize is enabled
Last modified: August 24, 2016

---

# Action wp_enqueue_scripts does not run, if Autoptimize is enabled

 *  [PascalBajorat](https://wordpress.org/support/users/pascalbajorat/)
 * (@pascalbajorat)
 * [11 years ago](https://wordpress.org/support/topic/action-wp_enqueue_scripts-does-not-run-if-autoptimize-is-enabled/)
 * Since the last WordPress update to version 4.1.3 and 4.2 the action hook “wp_enqueue_scripts”
   is not called.
 * When I enable Autoptimize my “wp_enqueue_scripts” functions will not called, 
   if I disable Autoptimize it runs without any problems.
 * [https://wordpress.org/plugins/autoptimize/](https://wordpress.org/plugins/autoptimize/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [11 years ago](https://wordpress.org/support/topic/action-wp_enqueue_scripts-does-not-run-if-autoptimize-is-enabled/#post-6054298)
 * Hi Pascal;
    Did a quick test, adding this;
 *     ```
       function my_scripts_method() {
           wp_enqueue_script( 'scriptaculous' );
       }
   
       add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
       ```
   
 * to the functions.php of my testblog and can’t reproduce I’m afraid.
 * Although 1.9.3 featured a change in how Autoptimized hooked into wordpress (at
   init instead of template redirect, with another priority as well), this was reverted
   the next day in 1.9.4, so I would have no idea what would cause this behaviour(
   which would mean almost no scripts would be added to your page, as every plugin
   and theme is bound to use that function).
 * What I would propose in order to identify the reason for this erratic behavior;
   *
   keep AO active and disable your other plugins (and maybe briefly swith to another
   theme as well) * check you phperror-log for relevant information * consider rolling
   back to AO 1.9.2 ([download here](https://downloads.wordpress.org/plugin/autoptimize.1.9.2.zip))
   to see if this indeed would solve the problem * if your code differs substantially
   from the one above (which I copy/pasted from the codex.wordpress.org), then post
   a (minimal) example here for me to test against.
 * Looking forward to cracking this little mystery! 😉
 * Kind regards,
    frank
 *  Thread Starter [PascalBajorat](https://wordpress.org/support/users/pascalbajorat/)
 * (@pascalbajorat)
 * [11 years ago](https://wordpress.org/support/topic/action-wp_enqueue_scripts-does-not-run-if-autoptimize-is-enabled/#post-6054486)
 * Hi Frank,
 * thank you very much for your quick response. I’m using this as base for my themes:
   [https://github.com/pascalbajorat/WordPress-Boilerplate/blob/master/functions.php](https://github.com/pascalbajorat/WordPress-Boilerplate/blob/master/functions.php)
 * And the function “FrontendScripts()” will not be called when I activate AO.
 * I will try it with version 1.9.2, maybe you have an idea so far.
 * Thank you and kind regards
    Pascal
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [11 years ago](https://wordpress.org/support/topic/action-wp_enqueue_scripts-does-not-run-if-autoptimize-is-enabled/#post-6054492)
 * Morning Pascal,
    Did some tests with that code, bringing it to the essenstial;
 *     ```
       class WordPressBoilerplate{
           static $ver = '2.0.0';
   
           function __construct(){
               add_action( 'wp_enqueue_scripts', array(__CLASS__, 'FrontendScripts') );
           }
   
           public static function FrontendScripts(){
               wp_enqueue_script( 'jquery' );
               wp_register_script('wp-h5bp-plugins', get_stylesheet_directory_uri().'/js/plugins.js', array('jquery'), self::$ver, true);
               wp_register_script('wp-h5bp-main', get_stylesheet_directory_uri().'/js/main.js', array('jquery', 'wp-h5bp-plugins'), self::$ver, true);
   
               wp_enqueue_script('wp-h5bp-plugins');
               wp_enqueue_script('wp-h5bp-main');
               }
       }
   
       $WordPressBoilerplate = new WordPressBoilerplate();
       ```
   
 * I have no problem getting this to work both with and without Autoptimize.
 * Maybe stating the obvious, but do take into account that you won’t actually see
   the seperate JS-files being called when AO is active, as AO will aggregate all
   JS-files into one minified “autoptimize_xyz.js”-file?
 * Have a nice sunday!
    frank

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Action wp_enqueue_scripts does not run, if Autoptimize is enabled’ is
closed to new replies.

 * ![](https://ps.w.org/autoptimize/assets/icon-256X256.png?rev=2211608)
 * [Autoptimize](https://wordpress.org/plugins/autoptimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autoptimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autoptimize/)
 * [Active Topics](https://wordpress.org/support/plugin/autoptimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autoptimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autoptimize/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/action-wp_enqueue_scripts-does-not-run-if-autoptimize-is-enabled/#post-6054492)
 * Status: not resolved