WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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%' );

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

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

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

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' );
share|improve this answer

Your Answer


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.