5

I have been customising the admin bar in version 3.3 to only have certain custom links with the following added to functions.php:

function mytheme_admin_bar_render() {
global $wp_admin_bar;

$wp_admin_bar->remove_menu('site-name');
$wp_admin_bar->remove_menu('new-content');
$wp_admin_bar->remove_menu('updates');
$wp_admin_bar->remove_menu('comments');
$wp_admin_bar->remove_menu('edit-profile');


$wp_admin_bar->add_menu( array(
    'id' => 'reports',  'title' => __( 'Reports'),  'href' => __('xyz.html'),
));
}
add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );

I'd now like to have the far right link that says Howdy, ..., function as a Logout button.

Does anyone have any suggestions on how achieve this?

-8

EDIT: This is obviously not a good idea if you want to be able to update - see comments below

As this site explains, you need to replace <?php printf(__(‘Howdy, %2$s!’), ‘profile.php’, $user_identity) ?> in the wordpress admin with in your case the word 'logout.' Then make the url be echo wp_logout_url();

  • 1
    And how do you run an update now? – fuxia Jun 17 '12 at 22:48
  • 6
    Changes in core files will be lost in updates. I don't recommend editing core files at all. – Jared Jun 18 '12 at 2:21
  • this is a dreadful idea, begging for constant maintenance... oh, I get it! (grr!) – webaware Dec 16 '12 at 2:46
4

Here is a simple solution I figured out by reverse engineering this plugin: http://wordpress.org/extend/plugins/dashboard-tweaks/

function custom_logout_link() {
    global $wp_admin_bar;
    $wp_admin_bar->add_menu( array(
        'id'    => 'wp-custom-logout',
        'title' => 'Logout',
        'parent'=> 'top-secondary',
        'href'  => wp_logout_url()
    ) );
    $wp_admin_bar->remove_menu('my-account');
}
add_action( 'wp_before_admin_bar_render', 'custom_logout_link' );
1

This should hit the spot:

function remove_old_logout() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_node('my-account');
}
add_action( 'wp_before_admin_bar_render', 'remove_old_logout' );

function newlogout() {
?>

<style type="text/css">
table#one-click01 tr td a:link,
table#one-click01 tr td a:visited {
    color:#CCCCCC;
    text-decoration: none;
}
table#one-click01 tr td a:hover,
table#one-click01 tr td a:active,
table#one-click01 tr td a:focus {
    color:#FAFAFA;
    text-decoration: none;
    }
table#one-click01 {
float:right;z-index:100000;position:fixed;right:0px;top:0px;background:#464646;padding-right:30px;padding-left:100px;border:0px;
}
body table#one-click01 tr td {
    height:25px;
    padding:3px 0 0 0;
    font-size:13px;
    font-family:sans-serif;
    line-height:1.5;
    color:#CCCCCC;
}
body.wp-admin table#one-click01 tr td {
    height:28px;
    padding-top:0px;
}
body.logged-in table#one-click01 tr td {
    padding-right:30px;
    border: 0px;
}
body.logged-in table#one-click01 {
    margin:0;border-collapse:collapse;border-spacing:0;
}
body.logged-in table#one-click01 tr td {
    vertical-align:middle;
    border:0;
}
</style>
<table id="one-click01" style="" border="0" cellspacing="0" cellpadding="0"><tr><td align=center valign=center>
<?php
    wp_get_current_user();
    $current_user = wp_get_current_user();
    if ( !($current_user instanceof WP_User) )
    return;
    $name = $current_user->display_name;
 ?>

<?php echo '
<a href="' . wp_logout_url() . '" title="' . esc_attr__('Log Out') . '">Howdy, ' . __($name) . '</a>'
; ?>

</td></tr></table>

<?php 
}
add_action( 'admin_bar_menu', 'newlogout' );
?>

Modified version of: http://wordpress.org/extend/plugins/one-click-logout/

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.