inject js after redirect

I figured out a solution that ended up being along the lines of the suggestions offered (though it felt like more work than I should have had to do just to inject some js on the page).

  1. I appended a variable to my redirection url:
    wp_safe_redirect(esc_url(add_query_arg(‘failed_authentication’, ‘1’, ‘/register’)));
  2. I registered the parameter variable using:
    add_query_vars_filter($vars)
  3. I registered a function with the wp_footer hook. Inside that function I retrieved the variable — get_query_var(‘failed_authentication’) — and printed my js/jQuery to inject the message (conditioned on that var).

Leave a Comment