How to Change WordPress Login Logo, Anchor Link and Redirect URL without using Plugin

Today, we are going to change the default wordpress login logo, logo anchor link, and redirect link after the user logins to the website.

CODE LINK:

PLEASE CHANGE THE URL WITH YOUR WEBSITE URL


function custom_login_redirect( $url, $request, $user ) {
    if ( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
        if ( $user->has_cap( 'administrator' ) ) {
            $url = admin_url();
        } else {
            $url = home_url( '/REDIRECT-URL-AFTERLOGIN/' );
        }
    }
    return $url;
}

add_filter( 'login_redirect', 'custom_login_redirect', 10, 3 );


function custom_login_logo() {
    ?>
    <style type="text/css">
        #login h1 a, .login h1 a {
            background-image: url(https://yourwebsite.com/path/image.png);
            height:65px;
            width:320px;
            background-size: contain;
            background-repeat: no-repeat;
            padding-bottom: 30px;
        }
    </style>
    <?php
}
add_action( 'login_enqueue_scripts', 'custom_login_logo' );

function change_login_logo_url() {
    return 'https://YOURWEBSITE.com/';
}
add_filter( 'login_headerurl', 'change_login_logo_url' );

function change_login_logo_url_title() {
    return 'Your Website Title';
}
add_filter( 'login_headertext', 'change_login_logo_url_title' );


/**
 * Disable admin bar
 */

function disable_admin_bar_for_non_admins(){
    if (!current_user_can('administrator')) {
        add_filter('show_admin_bar', '__return_false');
    }
}
add_action('after_setup_theme', 'disable_admin_bar_for_non_admins');

Gel Manalastas

I love to tinker and take things apart, and then put them together in new and better ways. I am at my best when looking for ways to improve things. Just tell me what is the issue and 'what' you want to accomplish. I'll find a way on 'how' to accomplish it. My strengths are completing things, finding ways to improve systems, making things simpler.

Leave a Comment

Your email address will not be published. Required fields are marked *

Get help with your website needs

Leave your contact details below and I will get back to you as soon as I can.