Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to change the login url from wp-login.php to simply 'login'. I'd been looking through another plugins source to find ways of doing it.

Some of the applicable parts that I've got so far:

register_activation_hook( __FILE__, 'my_plugin_activate' );
register_deactivation_hook( __FILE__, 'my_plugin_deactivate' );

add_action( 'init', 'my_plugin_rewrite' );
add_action( 'login_init', 'my_plugin_login_init' );
add_action( 'template_redirect', 'my_plugin_display' );

function my_plugin_activate() {
    add_rewrite_tag( '%login%', '([^/]+)');
    add_permastruct( 'login', '/%login%' );
    flush_rewrite_rules();
}

function my_plugin_login_init() {
    if ( '/wp-login.php' == $_SERVER['PHP_SELF'] ) {
        header( 'HTTP/1.0 404 Not Found' );
        global $wp_query;
        $wp_query->set_404();
        require TEMPLATEPATH . '/404.php';
        exit;
    }
}

function my_plugin_display() {
    global $wp_query;
    switch( $wp_query->query_vars['pagename'] ) {
        case 'login' :
            include( ABSPATH . '/wp-login.php' );
            exit;
            break;
    }
}

The problem I'm having is in the "my_plugin_display" function.

$wp_query->query_vars['pagename'] happens to be empty. How can I test if the url is at /login? Is this the right hook to use?

share|improve this question

1 Answer 1

You can try adding a query var using the 'query_vars' filter like so:

add_filter('query_vars', 'my_plugin_query_vars');
function my_plugin_query_vars($vars) {
    $vars[] = 'login';
    return $vars;
}

That may populate $wp_query->query_vars, if not I have successfully used the get_query_var function in one of my projects, try something like:

function my_plugin_display() {
    if(get_query_var('login')) {
        include( ABSPATH . '/wp-login.php' );
        exit;
    }
}
share|improve this answer

Your Answer

 
discard

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

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