简体   繁体   中英

How to change Wordpress dashboard login url to website URL?

I have a Wordpress website

www.example.com

Once a user goes to URL he sees Wordpress login page and below URL in the browser address bar.

www.example.com/wp-admin/....

I want to change that so when people go www.example.com they see the login page and the url in the browser address bar remains same www.example.com or in other words I dont want that slug and redirect text seen in the address bar. Is that possible to do?

I don't know that you can rewrite wp-admin , but you could create your own login code to display on the Home page. To start with, wp_login_form () displays a login form:

<?php wp_login_form(); ?>

You could add this code to a page template, or create a shortcode so it can be added via the Dashboard editor like this:

add_action( 'init', 'stackoverflow_login_shortcode' );
function stackoverflow_login_shortcode() {

    add_shortcode( 'stackoverflow-login-form', 'stackoverflow_login_form_shortcode' );

}
function stackoverflow_login_form_shortcode() {

    if ( is_user_logged_in() ) {
        return '<p>You are already logged in!</p>';
    }
    return wp_login_form( array( 'echo' => false ) );

}

Now you can add [stackoverflow-login-form] into a page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM