• Resolved Rose

    (@rosefields)


    I’m trying to customize the admin dashboard of the site I’m developing and want to change the WordPress logo to my logo. I’ve researched a lot of sites as well as these forums and found the same code. I don’t know what I’m doing incorrect but can’t get the logo to change. Here is the code I’m using in my functions.php file:

    function custom_logo() {
    echo '<style type="text/css">
    #header-logo { background-image: url('.get_bloginfo('template_directory').'/images/
    logo.png) !important; }
    </style>';
    }
    add_action('admin_head', 'custom_logo');

    I’ve tried uploading the images to various locations and don’t seem to be able to get it to work. I created an images folder where all the themes are located and placed the logo there. I uploaded the logo to the images folder of the current theme. I created an images folder in the root directory and uploaded the image there. I changed the image name to just “logo” so that I knew I wasn’t misspelling it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • View source and see what’s been churned out.

    That’ll tell you what your code is outputting and where it hopes to find the image. Then see if your image is in that place.

    If everything’s as it should be then check the css . The default position (since you haven’t specified it) is top left

    I use the ‘login_head’ hook which has worked pretty well in the past. Just make sure the url you supply is valid and pointing at your custom logo.

    You can additionally change where the logo links to and its title attribute quite easily.

    function custom_login_logo() {
    
    	$custom_logo = 'add your logo image path here'; ?>
    
    	<style type="text/css">
    		h1 a { background-image:url('<?php echo $custom_logo; ?>') !important; }
    	</style>
    
    	<?php
    	// Optionally change where the logo links to and the title attribute
    	// You will need to define 'custom_wp_login_url', 'custom_wp_login_title'
    	// callback functions yourself to make this work
    	add_filter('login_headerurl', 'custom_wp_login_url');		// Add link to home page, rather than www.remarpro.com
    	add_filter('login_headertitle', 'custom_wp_login_title');	// Change the title attribute
    
    }
    add_action('login_head', 'custom_login_logo');
    Thread Starter Rose

    (@rosefields)

    @richarduk: I checked the source and it showed me where it was looking for the image; I’m using a child theme and it was looking for it in the parent theme. I added the image there but it still doesn’t show up. Since I’m adding this to my functions.php file what css do I need look at to make any corrections?

    @dgwyer: I tried your code and made the changes you indicated but am a bit confused. Part of the code is above the <?php tag. When I put it above that tag in my file it prints an error code above the header on my website. When I put it below the tag it gives me an error code to the line that the code is on. I’ve tried using all the code you listed, just the top half, just the bottom half, put it above the php tag, below the tag, and other combinations but keep getting an error code.

    Thank you both for your help; I worked on this one part for about 10 hrs yesterday and already 4 hrs today. Maybe I’m just not seeing something correctly by now. In the past I’ve used a plugin to accomplish this but I am working to reduce the number of plugins I use for the sites I develop.

    To fetch an image from a child theme change template_directory to stylesheet_directory

    You don’t need to change the code snippet I posted at all. Just make sure it goes in your themes (or child themes preferably) functions.php file at the bottom somewhere before the closing PHP tag.

    Some times in PHP it is easier to close the PHP tag to output some HTML in a PHP function before re-openening the PHP tag. It’s just a commonly used approach.

    If you add the code and change the URL to a valid one (i.e. your logo) it should work fine.

    Thread Starter Rose

    (@rosefields)

    @dgwyer ah ha moment! the code does work – for another task on my list that I was wanted to accomplish. I logged out of the dashboard so I could log in as a different user and voila the login image was my logo.

    What I was trying to change was the logo to the left of the site title in the admin area. Which I just got changed. I just kept moving the code and rewriting it and finally ended up moving the “add action” line to the top of the function I’ve been trying to create. Once I did that it worked!

    Here’s what it looks like now:

    add_action('admin_head', 'custom_logo');
    function custom_logo() {
    echo '<style type="text/css">
    #header-logo { background-image: url('.get_bloginfo('stylesheet_directory').'/images/logo.png) !important; }
    </style>';
    }

    Thank you both for your help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘custom admin logo problem’ is closed to new replies.