Adding Your Items to the WordPress Admin Bar

Not so long ago I took up cross-posting on the Internet and searched for services for a long time, to which you can publish data automatically from your blogs, but as it turned out it's not so easy. For example, social network Vkontakte and Google+ do not want to do this. I think there are workarounds, but I haven't found them to be honest., whether there was no time, it was just lazy.

After scratching my turnip well, I decided that it’s not difficult for me to press a couple of buttons to send the written post to the wall in the social network. Hence the idea was born to find how to standard WordPress Admin Bar add custom buttons.

On one of the sites, I don't remember exactly which, I found the code especially even without a description, but everything was clear to me from the code and so. Always thought it was harder ).

Let's Start Building a Custom WordPress Admin Bar

First, open the functions file from your theme, where you can painlessly add your functions. This file is located at:
wp-content/themes/name of your theme/functions.php
In the open file, at the very end, add the code.

Consider the code of our Admin Bar in order. First function wp_admin_bar_init initializes our button in Admin Bar. This function checks, the user is logged in as an administrator and does he have the admin bar enabled. If all conditions successfully got true, then a special hook to the execution of the engine code also adds the execution of the function wp_admin_bar_links().

global $wp_admin_bar – method, which is an instance of the WP_Admin_Bar class. Further still easier. Inside a function wp_admin_bar_links() we describe variables with paths, where they should get when clicking on one of the menu items we create in the Admin Bar. array $links represents the rendered appearance of menu items.

And finally, add the item itself to the Admin Bar $wp_admin_bar->add_menu( array… . Below in the loop, sub-items are added from the array $links.

foreach ($links as $label => $url) {

 

The result of the work created AdminBar

admin bar wordpress уроки

In general, and all. I'm waiting for your comments, suggestions on how else you can use this code and tips for improving the code.

Another article on the topic: Adding a button to the admin bar. Add to Basket.


Buy WordPress hosting
/* WordPress tutor
Online tutoring services. List of courses I teach
  • Basic web design course;
  • Site layout;
  • General course on CMS WordPress and continuation of the course on template development;
  • Website development in PHP.
Read more on the page WordPress tutor
*/

Nikolaenko Maxim

Director of web studies ProGrafika. I am developing, website design and promotion. Always glad to new blog readers and good clients.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Templates for WordPress
The best hosting in Ukraine
Stable hosting for Drupal