• Hello there gods of code!

    I was wondering if any php goeroe can take a swing at my problem I have going on here. My html / css skills are pretty good, but PHP is like a different language. I can read it, I understand it but I can’t type it really good…

    The following, I want to customize my login-page with a branded logo. I know that is really easy to do to hack the login-css. That’s crap due updates will kill that adjustment. So I thought, what if I try doing it with the functions.php:

    function replace-wp-logo() {
        echo '<style type="text/css">
        h1 a { background-image:url('.get_bloginfo('template_directory').'/images/logo.png) !important; }
        </style>';
        }
        add_action('login_head', 'replace-wp-logo');

    Not that big of a deal, think this snippet is well known. For once who don’t know it, this replaces the WP logo to a custom logo. Just upload a new logo in your image folder in your theme (/images/logo.png) and make sure its 310×70. Note… if you want different dimensions you can, but than you have to customize the login file. Thats exactly I don’t want due I want to leave the updates files when upgrading WP to be left alone.

    So the thing i’m struggling with is to add code in this snippet what also changes the title and link of the logo. I don’t know if it can be done in the functions.php. I also want to use as less as possible plug-ins.

    The thing I tried is to add:

    function change_wp_login_url() {
        echo bloginfo(‘url’);
        }
        function change_wp_login_title() {
        echo get_option(‘blogname’);
        }
        add_filter(‘login_headerurl’, ‘change_wp_login_url’);
        add_filter(‘login_headertitle’, ‘change_wp_login_title’);

    But that is not working, also this kinda is where my knowledge of PHP exceeds myself. I copy pasted this from some kind of blog.

    Im constructing my own theme from scratch, due I want to learn and understand the Worpress codex and loop better than I did as so learing PHP. There still is allot of work to do, but you can take a look here (http://www.tekortschot.nl) maybe I made a flaw somewhere else and thats the reason this piece of code in the functions.php is failing.

    Thanks in advance, and with regards,
    Paul

Viewing 5 replies - 1 through 5 (of 5 total)
  • a:
    have you tried to set the width and height of the h1 a element in the login?

    this is the original code:

    h1 a {
    	background: url(../images/logo-login.gif) no-repeat top center;
    	width: 326px;
    	height: 67px;
    	text-indent: -9999px;
    	overflow: hidden;
    	padding-bottom: 15px;
    	display: block;
    }

    if you are able to overwrite the background image, you should be able to overwrite the other values as well.
    if needed, use the !important on each of the styles.

    b:
    in your second block of code, change all quotation marks to normal straight ' ones (example 'url').

    copying from articles does sometimes bring the ‘nice’ quotes (example ‘url’) with it – which will not work in the code.

    Thread Starter kortschot

    (@kortschot)

    How could I not have noticed that…. stupido!

    // verander WP-Logo login.php
        function my_custom_login_logo() {
        echo '<style type="text/css">
        h1 a { background-image:url('.get_bloginfo('template_directory').'/images/pad-naar-logo.png) !important; }
        </style>';
        }
        add_action('login_head', 'my_custom_login_logo');
    
        // verander de url op de login pagina
        function put_my_url(){
        return ('http://www.yourdomain.nl/'); // verander in de url van je website
        }
        add_filter('login_headerurl', 'put_my_url');

    Works like a charm, no more editing core files after a WP update.

    Thanks for reply!
    Paul

    if you have both issues fixed, please mark this thread as resolved – thanks.

    Hi kortschot and alchymyth
    Great work both of you! I just wanted to add something else to this, seeing as I found this via Google and I guess other’s will too. Also, can’t see anyone else having mentioned this in other related posts, which are now all locked down.
    When you hover over the image, it still shows Powered by WordPress; so I added extra code to change this too, extending what you guys did above:

    //changing the logo
    function my_custom_login_logo() {
        echo '<style type="text/css">
        h1 a { background-image:url('.get_bloginfo('template_directory').'/images/your-logo.png) !important; }
        </style>';
        }
        add_action('login_head', 'my_custom_login_logo');
    
        // changing the login page URL
        function put_my_url(){
        return ('http://www.yourdomain.com/'); // putting my URL in place of the WordPress one
        }
        add_filter('login_headerurl', 'put_my_url');
    
    // changing the login page URL hover text
        function put_my_title(){
        return ('Name of Your Website'); // changing the title from "Powered by WordPress" to whatever you wish
        }
        add_filter('login_headertitle', 'put_my_title');

    Feel free to close off the thread!

    Here is a way even easier than what you guys have and it avoids having to edit the functions.php file each time. Create a plugin. You can use the WordPress Codex and the various key terms used for other aspects of a website.

    /*
    Plugin Name: Custom Login Link and Hover
    Plugin Author: Nicole Santillo of PittBull Secure Technologies
    Description: Changes the default login link of wordpress.org to your blog's domain.
    Version: 1.0
    */ 
    
    // changing the login page URL
        function put_my_url(){
        return bloginfo('url'); // changes the url link from wordpress.org to your blog or website's url
        }
        add_filter('login_headerurl', 'put_my_url');
    
    // changing the login page URL hover text
        function put_my_title(){
        return bloginfo('name'); // changing the title from "Powered by WordPress" to whatever you wish
        }
        add_filter('login_headertitle', 'put_my_title');

    This avoids having to change the code every time you create a new site either for yourself or for someone else.

    The code above will also work in your functions.php but I find doing this as a plugin easier for me because i don’t have to keep adding it every time for each client. It is just a quick upload.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘functions.php change logo and link login page’ is closed to new replies.