0

I want to replace the default WordPress admin bar logo to my custom logo which is a PNG file. I have tried a code it's not working.

function custom_logo_admin_header() {
echo '
<style type="text/css">
#wp-admin-bar-wp-logo > .ab-item .ab-icon { 
background-image: url(' . get_bloginfo('stylesheet_directory') . '/images/wp-logo.png)   !important; 
background-position: 0 0;
}
#wpadminbar #wp-admin-bar-wp-logo.hover > .ab-item .ab-icon {
background-position: 0 0;
}   
</style>
';
}

add_action('admin_bar_menu', 'custom_logo_admin_header');
1

I think the path to the image is wrong, use get_stylesheet_directory_uri() to retrieve the style.css path. If this isn't it let me know and I will take a closer look.

I just dug out an example which worked for me in the past:

function my_login_logo() { ?>
 <style type="text/css">
    body.login div#login h1 a {
        background-image: url(PATH_TO_FILE);
    }
</style>
<?php }

Update: I really should read more carefully before replying! Ok how about this ->

function custom_logo_admin_header() { ?>
    <style type="text/css">
      #wp-admin-bar-wp-logo > .ab-item .ab-icon { 
          background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/images/wp-logo.png)   !important; 
          background-position: 0 0;
      }
      #wpadminbar #wp-admin-bar-wp-logo.hover > .ab-item .ab-icon {
        background-position: 0 0;
      }   
    </style>
<?php
}

New Update: This one is as well locally tested!

All above are off track and this will lead to the best result.

function no_wp_logo_admin_bar_remove() {        
    ?>
        <style type="text/css">
            #wpadminbar #wp-admin-bar-wp-logo > .ab-item .ab-icon:before {
                content: url(<?php echo get_stylesheet_directory_uri(); ?>/images/wp-logo.png)   !important;
                top: 2px;
            }

            #wpadminbar #wp-admin-bar-wp-logo > a.ab-item {
                pointer-events: none;
                cursor: default;
            }   
        </style>
    <?php
}
add_action('wp_before_admin_bar_render', 'no_wp_logo_admin_bar_remove', 0);

Now about there where to put this, you can add it in the functions.php and you can put it in the plugins main .php file, which as well will do the trick. Let me know if this worked.

| improve this answer | |
  • Changed Like this background-image: url(' . get_stylesheet_directory_uri() . '/images/wp-logo.png) !important; the default logo got removed.but it is not loading the new one. – John Jul 24 '14 at 10:38
  • 1
    bro I am asking about the admin-bar logo not login page logo – John Jul 24 '14 at 10:40
  • Will this work if use this code in plugin? or I have to put the code in function.php? – John Jul 24 '14 at 10:51
  • bro I have small doubt, What's that the 0 means in add_action – John Jul 24 '14 at 11:16
  • 1
    That's the priority of the call, default is 10, 0 is pretty high, before everything else to precise. – sogathon Jul 24 '14 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.