Support » Plugins » Hacks » some wp admin bar related snippets

  • Resolved Ovidiu


    first of all, here is the site I will be talking about:

    I am using a php file from inside mu-plugins to modify the wp admin bar to my likings and need some help.

    a) the part on the far left of the bar where it says: is generated by this snippet:

    function addLinkHome( $wp_admin_bar) {
                            $wp_admin_bar->add_menu( array( 'title' => __( '' ), 'href' => '' ) );
                    <style type="text/css">
                    #wp-admin-bar-zice-ro { background: #FA0502 url('') no-repeat left top;}
                    add_action( 'admin_bar_menu', 'addLinkHome', 0 ); //try add_action( 'admin_bar_menu', 'addLinkMenu', 999 );

    I was trying to put the favicon of the site in front of it just like the avatar that appears when you are logged in, check this screen shot:

    a) The second part from the left, where it says “Blog aleator” should actually be on the far right hand side but I can’t position it there. Here is the code that generates it:

    function addLinkRandom( $wp_admin_bar) {
                                    $wp_admin_bar->add_menu( array( 'title' => __( 'Blog aleator' ), 'href' => '' ) );}
                    add_action( 'admin_bar_menu', 'addLinkRandom', 0 ); //try add_action( 'admin_bar_menu', 'addLinkMenu', 999 );

    Unfortunately this code generates the menu into the .quicklinks part. How to get it to show on the far right hand side?

    c) what is the difference between these two snippets as c1) works and c2) doesn’t


    function addNetworkComments() {
                                    global $wp_admin_bar;
                                   if ( is_user_logged_in() ){
                                    $wp_admin_bar->add_menu( array( 'parent' => 'comments', 'title' => __( 'Discutiile mele'),
                                    'href' => admin_url( 'index.php?page=my_network_comments' )
                                                                                                            ) );
                                    add_action('wp_before_admin_bar_render', 'addNetworkComments', 0);


    function addNetworkComments( $wp_admin_bar) {
                                    if ( is_user_logged_in() ){
                                    $wp_admin_bar->add_menu( array( 'parent' => 'comments', 'title' => __( 'Discutiile mele'),
                                    'href' => admin_url( 'index.php?page=my_network_comments' )
                                                                                                            ) );
                                    add_action('admin_bar_menu', 'addNetworkComments', 0);

Viewing 15 replies - 1 through 15 (of 15 total)
  • anyone?

    I was just experimenting with this.

    These are what I came up with:

    function add_menu_left( ) {
                    global $wp_admin_bar;
                    <CODE FOR LEFTHAND MENU>                              }
    add_action('admin_bar_menu', 'add_menu_left', 10);
    function add_menu_right( ) {
                    global $wp_admin_bar;
                    <CODE FOR RIGHTHAND MENU>                                                                                                }
    add_action('wp_before_admin_bar_render', 'add_menu_right', 0);

    thx Ipstenu. that is halfway there: have a look: its on the right but not where the search box used to be in the original unmodified admin bar. I am looking to get this to the far right and replace the search box with it…

    it looks like I can’t do this with CSS as its inside a complex structure…

    there msut be a way to get this to replace the search box….

    any idea on c) ?

    Looking at

    The search is wrapped in

    <div id="adminbarsearch-wrap">
    	                                <form action="<?php echo home_url(); ?>" method="get" id="adminbarsearch">
    	                                        <input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />
    	                                        <input type="submit" class="adminbar-button" value="<?php _e('Search'); ?>"/>

    Unlike the quicklinks part of the site, which is a foreach on the array. There is no way to remove it using PHP – it’s baked directly in the render() method for the admin bar class. BUT.

    To hide it, just toss this in your CSS #wpadminbar #adminbarsearch {display: none;}

    (Per – Helen says you can’t remove it apparently, and I believe her. She haz the smart)

    I did hide it already. please see live:

    as stated I would like to get this code to show on the top right hand side and replace the search code, I mean appear in the same place.

    see a more detailed description in this screen shot please:

    I hope that explains it better than I could with words 🙂

    What I’m getting at is that you’d probably have to wrap it in a div, like <div id="adminbarsearch-wrap"> to make it show on the far far far right.

    ok, but from the admin bar code you posted above from trac it looks like this:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    and I can only inject it into the <div class=”quicklinks”> part via $wp_admin_bar->add_menu( array( 'title' => __( 'Blog aleator' ), 'href' => '' ) );}

    I understand now what you are hinting at but I do not know how to get it over there… since the search is inside <div id=”adminbarsearch-wrap”> I can’t create a new one since IDs must be unique.

    am I missing the obvious here? sorry if I do

    and how would I wrap this: $wp_admin_bar->add_menu( array( 'title' => __( 'Blog aleator' ), 'href' => '' ) );} into a div?

    Yeah, I don’t know either which is why I didn’t just post the code 😉

    In THEORY if you could echo a </div><div class="quicklinks"> in between the left and righthand stuff, it might work.

    @the anonymous moderator who felt the need to moderate my post, I take it you are referring to this rule:

    according to that, I can post up to ten lines of code, so I insist in doing so:

    <div class="quicklinks">
    	<ul><?php foreach ( (array) $this->menu as $id => $menu_item ) : ?>
    		<?php $this->recursive_render( $id, $menu_item ) ?>
    		<?php endforeach; ?></ul>
    <div id="adminbarsearch-wrap">
    	<form action="<?php echo home_url(); ?>" method="get" id="adminbarsearch">
    		<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />
    		<input type="submit" class="adminbar-button" value="<?php _e('Search'); ?>"/></form></div>


    back to the issue at hand, I understand now. thanks for the hints though. you are right but I need to figure out a way to insert that piece of html in there.
    have to read up on this: $wp_admin_bar->add_menu( array( 'title' => __( 'Blog aleator' ), 'href' => '' ) );} and see if one can pass some code or formatting along with the link, but since it injects it exactly into the ul menu as a li tag there won’t be a chance of that I guess 🙁

    will leave this issue as open maybe someone will add some more ideas to it.

    The only reason we (yes we, I are a mod) moderate short code bits is when they trip the spam filter. Don’t take it personally, and don’t bite the hands that mod you 😉

    Have you looked at ? The code in tehre may have clues!

    @ipstenu: I know you’re a mod, that’s why I am nice to you (just kidding 😉

    will have a look at that one – maybe the author can help or has an idea

    Like you I’m trying to have some text or picture at the far right of the admin bar.
    I just saw that somehow you managed to do it but I can’t find anything helping me to reach the same result as you.
    Could you tell me how you did it please ?
    Thank you very much in advance

    hehe, sure thing!

    //add the random link to the admin bar
        function addLinkRandom( $wp_admin_bar) {
            global $wp_admin_bar;
            $wp_admin_bar->add_menu( array( 'title' => __( 'Blog aleator' ), 'href' => '' ) );
            <style type="text/css">
            #wpadminbar .quicklinks ul #wp-admin-bar-blog-aleator { float: right !important;
    background: transparent url('') no-repeat left top!important;
    margin:1px 4px 0!important;
    #wpadminbar .quicklinks ul #wp-admin-bar-blog-aleator a {
    border:none !important;
            <?php }
        add_action( 'wp_before_admin_bar_render', 'addLinkRandom', 0 ); //try add_action( 'admin_bar_menu', 'addLinkMenu', 999 );

    and here is the link to where I got that solution from:

    Hello again thank you so much for your quick answer. It’s working perfectly well. ^^
    Have a nice day and thank you again

    you’re welcome.
    I totally forgot to close and update this thread 🙂

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘some wp admin bar related snippets’ is closed to new replies.