Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Zodiac1978
Created December 5, 2020 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zodiac1978/fc8bd328e36b1a016f92567e74729113 to your computer and use it in GitHub Desktop.
Save Zodiac1978/fc8bd328e36b1a016f92567e74729113 to your computer and use it in GitHub Desktop.
Add new menu for custom toolbar items
<?php
/**
* Plugin Name: Custom Toolbar
* Description: Add custom toolbar items in frontent to check page and/or site.
* Plugin URI: https://torstenlandsiedel.de
* Version: 1.0
* Author: Torsten Landsiedel
* Author URI: http://torstenlandsiedel.de
* Licence: GPL 2
* License URI: http://opensource.org/licenses/GPL-2.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Add toolbar item
*
* @param Object $admin_bar WPAdminBar object.
*/
function add_admin_bar_items( $admin_bar ) {
// Bail early if no admin.
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
// Bail early if in admin area.
if ( is_admin() ) {
return;
}
$menu = array(
array(
'id' => 'quick_menu',
'title' => 'Quick Menu',
),
array(
'id' => 'check_w3c',
'title' => 'Validate HTML',
'href' => 'https://validator.w3.org/nu/?doc=' . rawurlencode( get_permalink() ),
'parent' => 'quick_menu',
'meta' => array(
'title' => __( 'Menu Title', 'textdomain' ),
'target' => '_blank',
),
),
);
foreach ( $menu as $args ) {
$admin_bar->add_node( $args );
}
}
add_action( 'admin_bar_menu', 'add_admin_bar_items', 500 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment