I worked out a way to conditionally print a script to the head of the page, but not to actually enqueue it.
The code depends on the presence of the wp_shake_js
callback that is conditionally added to the login page on login failure. If that hook is present, the assumption is that the login failed.
Unfortunately, that callback is hooked to login_head
which executes after login_enqueue_scripts
so you need to print the script, rather than enqueue it.
add_action(
'login_head',
function() {
if (has_action('login_head','wp_shake_js')) {
echo '<script type="text/javascript">alert("howdy");</script>';
}
},
13
);
I can’t help but think there is a better way, but I can’t find it (and I am running out of time for WPSE this morning 🙂 ).