Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



WordPress - Add but...
 
Share:
Notifications
Clear all

[Solved] WordPress - Add buttons to the AdminBar

2 Posts
1 Users
0 Reactions
1,370 Views
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

Recent WordPress versions show a black AdminBar when you're logged in - you could add buttons here to make some admin tasks easier.

For Tweaking4All I needed buttons to make moderating comments easier, and below you will see how I did that. You'll need to add the function to the functions.php file.

function adminbar_add_t4aButtons( $wp_admin_bar ) {
$url = admin_url( 'edit-comments.php?comment_status=moderated' );
$args = array(
'id' => 't4a_nl_pending',
'title' => 'Modereer',
'href' => $url,
'meta' => array('target' => '_self')
);
$wp_admin_bar->add_node($args);
}
add_action( 'admin_bar_menu', 'adminbar_add_t4aButtons', 999 );

As you can see, first we build an URL to one of the admin pages, in this case the overview of comments awaiting moderation - we use the function admin_url() followed by "edit-comments.php?comment_status=moderated", which is the link to the pending comments page. You can use any link you'd like, this is just an example.

We glue all this into an array with id (unique name), title (button text), href (the link), and meta (in this case so the link opens in the same browser tab).

Next we add the array to $wp_admin_bar so WordPress knows about it.

You can repeat the array and $wp_admin_bar stepts in the same function, as many times as needed.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

For reference: WordPress CODEC - AddNode


   
ReplyQuote
Share: