Support » Plugin: Autoptimize » How to load load javascript code AFTER combined autoptimize.js in footer

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Frank Goossens

    (@futtta)

    afraid AO is active long after the wp script queue has been processed (AO intercepts the full HTML from WordPress and works on the CSS & JS in that), so priority has no impact what-so-ever.

    so how can you accomplish loading JS after the AO’ed JS? the easiest way would be to change the “injection point” that AO uses for JS (when in footer). you can do that by using the API, as shown in this example;

    add_filter('autoptimize_filter_js_replacetag','maxbond_js_replacetag',10,1);
    function maxbond_js_replacetag($replacetag) {
            return array("<!-- injectjs -->","replace");
            }

    then in your (child) theme’s footer.php, insert <!-- injectjs --> where you’d want AO to inject the autoptimized JS (before wp_footer() I guess) and you should be good to go (obviously you’ll have to exclude the javascript code you want to load after the AO’ed JS).

    hope this helps,
    frank

    Thread Starter Max Bond

    (@max-bond)

    Ок! Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to load load javascript code AFTER combined autoptimize.js in footer’ is closed to new replies.