web dev & more!

Custom Admin Toolbar in WordPress

Published: July 31, 2014

I spend a lot of time on StackOverflow, as most people in any programming field do. Well, when I get time, I like to try and answer questions to give back to the community. Sometimes, I can be helpful. Not always, but sometimes.

Yesterday was one of those days. A question came up, about creating a custom interface with the WordPress admin bar. Seeing as how I’d never tried this, I thought I’d give it a shot and figure it out.

carrey-typing

After being sidetracked by actual work, I finally got to work on the question and came up with a solution.

add_action('wp_before_admin_bar_render', 'change_admin_bar',999);

function change_admin_bar() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_node('edit')

    $args = array(
        'id' => 'edit',
        'title' => 'Edit Backend',
       'href' => get_edit_post_link(),
    );

    $wp_admin_bar->add_node($args);
}

This code, when placed in the functions.php file of your theme, will remove the ‘Edit Post’ button from the admin bar, and then replace it with a button labeled ‘Edit Backend.’ It’s a super simple piece of code and there’s tons more that can be done with this kind of thing. You can tweak your admin toolbar to your heart’s content.

If you’re looking to do more than this, you can always go to the Codex to get more info or here.

Oh! And this is the link to Stack Overflow thread.

freinds-clapping

I don’t get to be useful on that website too often as there are so many brilliant minds, it’s easy to get cluttered.