Last active
October 9, 2024 00:32
-
-
Save paaljoachim/8f6ec97d4317b4bf4719 to your computer and use it in GitHub Desktop.
Adjusting the WordPress top admin toolbar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Example 2. Adding two nodes (sub menu links) to the site name menu. | |
// | |
// If your using the code in the beginning of your functions.php file then include the <?php before the below code. | |
// The following code adds a media library and a plugins link to the site name drop down menu. | |
add_action( 'admin_bar_menu', 'add_links_to_admin_bar',999 ); | |
function add_link_to_admin_bar($wp_admin_bar) { | |
// adds the child node media library to site name parent node | |
$wp_admin_bar->add_node( array( | |
'parent' => 'site-name', | |
'id' => 'media-libray', | |
'title' => 'Media Library', | |
'href' => esc_url( admin_url( 'upload.php' ) ), | |
'meta' => false | |
)); | |
// adds the child node plugins to site name parent node | |
$wp_admin_bar->add_node( array( | |
'parent' => 'site-name', | |
'id' => 'plugins', | |
'title' => 'Plugins', | |
'href' => esc_url( admin_url( 'upload.php' ) ), | |
'meta' => false | |
)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Example 3. Adding a top level node I named Custom Made having it link to an external web site. | |
// Adding two nodes (sub menu links) Media Library and Plugins to the Custom Made menu. | |
// | |
// The following code adds a top level link and media library and plugins submenu links to the Custom Made drop down. | |
add_action( 'admin_bar_menu', 'add_nodes_to_admin_bar',999 ); | |
function add_nodes_to_admin_bar($wp_admin_bar) { | |
// adds a top level parent node I called Custom Made | |
$wp_admin_bar->add_node( array( | |
'id' => 'custom', | |
'title' => 'Custom Made', | |
'href' => 'http://easywebdesigntutorials.com/', // Top level link Custom Made links to an external web site. | |
)); | |
// adds the child node Media Library to Custom Made | |
$wp_admin_bar->add_node( array( | |
'parent' => 'custom', | |
'id' => 'media-libray', // If you reuse media library in two locations then the id name of the second link needs to be different. | |
'title' => 'Media Library', | |
'href' => esc_url( admin_url( 'upload.php' ) ), | |
'meta' => false | |
)); | |
// adds the child node Plugins to Custom Made | |
$wp_admin_bar->add_node( array( | |
'parent' => 'custom', | |
'id' => 'plugins', | |
'title' => 'Plugins', | |
'href' => esc_url( admin_url( 'plugins.php' ) ), | |
'meta' => false | |
)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example 5. Remove the admin toolbar. | |
// | |
// The following code removes the admin toolbar. | |
add_filter('show_admin_bar', '__return_false'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment