Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Complete version of custom toolbar plugin
<?php
/**
* @package MyToolbar
*/
/*
Plugin Name: MyToolbar
Plugin URI: http://www.webniraj.com
Description: This plugin creates a custom toolbar
Version: 1.0
Author: Niraj Shah
Author URI: http://www.webniraj.com/wordpress/
*/
// function to run before menu is rendered
add_action( 'wp_before_admin_bar_render', 'preload_my_toolbar' );
// function to add items to toolbar
add_action( 'admin_bar_menu', 'my_toolbar' );
// forces toolbar to show to all users
add_filter( 'show_admin_bar', '__return_true' );
// placeholder function
function preload_my_toolbar() {
global $wp_admin_bar;
// remove WordPress logo
$wp_admin_bar->remove_node('wp-logo');
// remove search button
$wp_admin_bar->remove_node('search');
}
// placeholder function
function my_toolbar() {
global $wp_admin_bar;
// add a single link
$wp_admin_bar->add_node( array(
'id' => 'my-link-one',
'title' => 'Item 1',
'href' => site_url()
) );
// add a item
$wp_admin_bar->add_node( array(
'id' => 'my-search',
'title' => 'Search',
'href' => '#',
'parent' => 'top-secondary'
) );
// add a sub-item
$wp_admin_bar->add_node( array(
'id' => 'my-google-search',
'title' => 'Google',
'parent' => 'my-search',
'href' => 'http://www.google.com',
'meta' =>array( 'target' => '_blank' )
) );
// add another sub-item
$wp_admin_bar->add_node( array(
'id' => 'my-bing-search',
'title' => 'Bing',
'parent' => 'my-search',
'href' => 'http://www.bing.com',
'meta' =>array( 'target' => '_blank' )
) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.