Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using a function that redirects the user to a custom page, rather than wp-login in the event of errors. In my case I am using the Http Referer function to send the user back to the same page because I have the login form in a modal. How can I execute a function on the redirected page, so that the page automatically opens the modal?

This is the code for the redirect in the event of an error:

add_filter('login_redirect', '_catch_login_error', 10, 3);
function _catch_login_error($redir1, $redir2, $wperr_user) {
    $rurl = $_SERVER['HTTP_REFERER'];
    if(!is_wp_error($wperr_user) || !$wperr_user->get_error_code()) return $redir1;
        switch($wperr_user->get_error_code()) {
            case 'incorrect_password': 
            case 'empty_password': 
            case 'invalid_username': 
            default: wp_redirect($rurl); }
        return $redir1;

This code courtesy of

The function I want to execute after redirect is:

add_action('genesis_before_post', 'force_open_modal_1');
function force_open_modal_1() { ?>
    <script type="text/javascript">
<?php }

Is this possible?

share|improve this question
Try add_query_arg( 'key', 'value' ); - then hook into wp_query() with your fn, and switch with get_arg( 'key' ) if you want to trigger or abort. – kaiser Oct 3 '12 at 15:56
Thanks for the reply, how do I go about hooking the _catch_login_error into a wp_query? I'm a little confused – Kyle Oct 3 '12 at 17:18
Not "a" wp_query. Into the equally named hook (or maybe into template_redirect or whatever fits). – kaiser Oct 4 '12 at 6:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.