• I am trying not to repeat a post I made in the Plugins forum. This is just a more general question. I want to reverse or negate an action for a plugin only on certain pages. But I need to make sure the file I created with the script to override the plugin javascript gets loaded last. Is there a known or common way to make sure a file – let’s call it custom.js – gets called last when the page is loading in the browser? Just adding an action through wp_enqueue_scripts in the functions.php file doesn’t seem to make it load last. It loads. But the plugin loads later and kills what I was trying to reverse or negate.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    First of all, be sure you specify your script reference should go in the footer when you call wp_enqueue_script(). The key to getting it to load later is when you add your action hook, specify a large priority number instead of letting it default to 10. As long as your priority is later/larger than the one used by the plugin, yours should load later.

    The only reason it wouldn’t is if WP sees some dependency that needs to be resolved by loading yours first. Another thing you could try is to specify the plugin script as a dependency for your script. Then WP should try to load the dependency first, even with the same priority argument.

    Thread Starter johnwp413

    (@johnwp413)

    I may need a little more advice/help. The current plugin loads just before the </body> </html> This is clearly after the footer scripts load. When I tried putting it in the footer, it loaded later but just not at the end. Is it possible that WP overrides priorities? In other words, does it sort of collect scripts and load them in its own way?

    Changing the dependencies may be my next effort, but for the plugin it may be tricky.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to make a jQuery script the last action’ is closed to new replies.