Home >CMS Tutorial >WordPress >How to Customize the WordPress ToolBar
This article demonstrates how to customize the WordPress admin bar (toolbar) using a custom plugin. The WordPress Admin Bar API, specifically the WP_Admin_Bar
class, provides methods like add_node()
and remove_node()
for manipulating toolbar items.
The process involves creating a plugin file (admin-bar.php
) within the /wp-content/plugins/
directory. This plugin allows for adding, removing, and rearranging toolbar elements.
The article details how to:
Remove the entire toolbar: Using add_filter('show_admin_bar', '__return_false');
Remove specific toolbar items: Utilizing remove_node()
with the item's ID (found in the HTML source code). The article provides examples of removing the WordPress logo, customize link, and comments link.
add_node()
with an associative array specifying the item's ID, title, link (href
), and other attributes (like parent
for submenus and meta
for additional HTML attributes). The article shows adding a SitePoint link and a sub-menu item for the SitePoint forums.The article concludes with a FAQ section addressing common questions about customizing the WordPress toolbar, covering topics such as changing colors, adding logos, creating responsive designs, and managing dropdown menus. Remember that the code examples can also be added to your theme's functions.php
file, though using a plugin is generally recommended for better organization and maintainability.
This article is part of a series created in partnership with SiteGround. Thank you for supporting the partners who make SitePoint possible.
The above is the detailed content of How to Customize the WordPress ToolBar. For more information, please follow other related articles on the PHP Chinese website!