Title: Enqueue script after Autoptimize aggregate
Last modified: March 28, 2025

---

# Enqueue script after Autoptimize aggregate

 *  Resolved [MarcGuay](https://wordpress.org/support/users/marcguay/)
 * (@marcguay)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/enqueue-script-after-autoptimize-aggregate/)
 * I am enqueuing the external Google Maps API with a callback to one of my JS scripts.
   The API is loading before the Autoptimize aggregate script and so it is failing
   to find the callback function. Is there a way to ensure the API script is added
   after? Or do I need to exclude the script with the callback and all of its dependencies?
   Thank you.

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

 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/enqueue-script-after-autoptimize-aggregate/#post-18389283)
 * best would be to use AO’s API to change the “injection point” of the aggregated
   JS, see below code example which assumes a comment `<!-- injectjs /-->` in the
   HTML (ideally footer) which will be replaced by the HTML for the aggregated JS;
 *     ```
       add_filter( 'autoptimize_filter_js_replacetag', 'my_ao_override_js_replacetag', 10, 1 );
       function my_ao_override_js_replacetag( $replacetag ) {
           return array('<!-- injectjs /-->', 'replace' );
       }
       ```
   
 * hope this helps,
    frank
 *  Thread Starter [MarcGuay](https://wordpress.org/support/users/marcguay/)
 * (@marcguay)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/enqueue-script-after-autoptimize-aggregate/#post-18392149)
 * Beautiful, works like a charm, thanks!
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/enqueue-script-after-autoptimize-aggregate/#post-18392215)
 * you’re welcome, feel free to [leave a review of the plugin and support here](https://wordpress.org/support/plugin/autoptimize/reviews/#new-post)!
   🙂

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

The topic ‘Enqueue script after Autoptimize aggregate’ 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: [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * Last activity: [1 year, 2 months ago](https://wordpress.org/support/topic/enqueue-script-after-autoptimize-aggregate/#post-18392215)
 * Status: resolved