Is there a hook to keep scripts that are included with widgets, persistent during the admin-ajax.php process?

I use jQuery show() to open an element within a widget and the element should remain closed until clicked, and that works as expected. However when the widget is saved and WP is doing ajax at admin-ajax.php, the the function fails and opens without any interaction. If the page is reloaded, the function returns to normal.

The function is running from a file myscript.js and loaded in admin_enqueue_scripts action.


<span class="button handle">View Details</span>
<div class="element">this is detail</div>

I suspect the widget is then at admin-ajax.php and the JS is not detected.

1 Answer 1


After deep meditation and a meeting with dally the llama (maybe it was an alpaca, I was quite high), I've defined a solution.

Use the widget-updated var to reload the JS function on widget save.

$(document).on('widget-updated', function(event, widget) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.