0

In the admin section, the commments bubble is on the left side of the toolbar. I know how to remove the bubble. What I can't figure out is how to move it to the right hand side of the toolbar (next to 'Howdy, [username]).

Any ideas?

3 Answers 3

2

After you have removed the comments bubble, you add it again. The trick is that in the $args of add_node you have to set parent to top-secondary.

So it will look like this:

add_action( 'admin_bar_menu', 'wpse227079_toolbar_link_to_bubble', 999 );

    function wpse227079_toolbar_link_to_bubble ( $wp_admin_bar ) {
        $args = array(
            'id'    => 'wp-admin-bar-comments',
            'parent'=> 'top-secondary',
            'title' => 'QQ',
            'href'  => 'QQ',
            'meta'  => array( 'class' => 'QQ' )
        );
        $wp_admin_bar->add_node( $args );
    }

Title needs the full html of the bubble, href the link where it is going and meta the class for the list item. You'll have to delve into the source code of the admin bar to find the right QQ's for the bubble.

2
  • Just in case anyone is wondering: it is not possible to simply change the parent setting by writing to the $wp_admin_bar object. This object can only be accessed by the add and remove actions.
    – cjbj
    May 19, 2016 at 7:20
  • 1
    Thanks. This basically answered my question. You can see what I actually did in my answer below.
    – Moshe
    May 19, 2016 at 9:11
1

One way to move it to the very right would be like this:

#wp-admin-bar-comments {
  float: right !important;
}

This will put it to the right of the Howdy message. I am not 100% sure if you want it on a specific side.

1

Based on cjbj's answer above, this is what I did...

I went to /wp-includes/admin-bar.php and copied the relevant code with a slight modification (see below) into my plugin. Here is the end result:

if ( !current_user_can('edit_posts') )
    return;

$awaiting_mod = wp_count_comments();
$awaiting_mod = $awaiting_mod->moderated;
$awaiting_text = sprintf( _n( '%s comment awaiting moderation', '%s comments awaiting moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) );

$icon  = '<span class="ab-icon"></span>';
$title = '<span id="ab-awaiting-mod" class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '" aria-hidden="true">' . number_format_i18n( $awaiting_mod ) . '</span>';
$title .= '<span class="screen-reader-text">' . $awaiting_text . '</span>';

$wp_admin_bar->add_menu( array(
    'id'    => 'comments',
    'parent' => 'top-secondary',
    'title' => $icon . $title,
    'href'  => admin_url('edit-comments.php'),
) );

All I did was add the 'parent' => 'top-secondary' line (as per cjbj's suggestion). This does exactly what I need it to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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