This code adds a menu item called “Snippets” to the WordPress Admin Bar, allowing users to quickly access Code Snippets Pro ❤️.
Add a “Snippets” Custom Menu Item to the WordPress Admin Top Bar

View on…
See the code…
<?php
/**
* Add "Snippets" Link to WordPress Admin Top Menu Bar [SnipSnip.pro]
* https://snipsnip.pro/s/810
*
* HARDENED 2026-08-07: the toolbar item was added for every logged-in user with an
* admin bar, including Subscribers and customers on the storefront. Clicking it landed
* them on a "you do not have permission" screen, and it advertised which plugin runs
* the site. It is now gated on the same capability Code Snippets itself uses.
*/
if( !class_exists('Custom_Snippets_Menu') ) {
// Add a "Snippets" menu item link to top menu bar in the WordPress Admin - https://snipsnip.pro/s/810
class Custom_Snippets_Menu {
function __construct() {
add_action('admin_bar_menu', array($this, 'add_toolbar_items'), 100);
}
function add_toolbar_items($admin_bar){
// Code Snippets filters its own required capability; honour it if present,
// otherwise fall back to manage_options.
$cap = apply_filters('code_snippets_cap', 'manage_options');
if ( ! current_user_can( $cap ) ) {
return;
}
$admin_bar->add_menu( array(
'id' => 'snippets-page',
'title' => 'Snippets',
'href' => admin_url('admin.php?page=snippets'),
'meta' => array(
'title' => __('Code Snippets Pro'),
),
));
}
}
new Custom_Snippets_Menu();
}
Leave a Reply