WordPress removes the specified items in the "My Site" pop-up menu in the upper left corner of the admin panel

888u

Last update at :2024-07-06,Edit by888u

In WordPress, the toolbar at the top of the admin background is generated by the WP_Admin_Bar class, so we can use the remove_node() method of this class to remove the items specified in it.

Grammar

WP_Admin_Bar::remove_node( string $id )

Delete a node.

Parameters

$id: ( string ) (required) The ID of the project.

More information

This function removes an item from the toolbar. Toolbar items are also called "nodes".

Finding toolbar node ID

The node ID can be found in the HTML source code of any WordPress page with a toolbar. Find list items whose ID starts with "wp-admin-bar-". For example, the list item ID for the WordPress logo on the left side of the toolbar is "wp-admin-bar-wp-logo":

Remove "wp-admin-bar-" from the list item IDs to get the node ID. In this example, the node ID is "wp-logo".

Note: You can also view all node IDs through the example of get_nodes().

Example

Remove the "Manage Comments" submenu under each site in the site list in "My Sites" in multisite mode.

/**
 * Removed manage comments menu from site list.
 *
 * @param WP_Admin_Bar $wp_admin_bar WP_Admin Bar instance.
 */
function remove_sites_edit_comments( $wp_admin_bar ) {
    foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
        $wp_admin_bar->remove_node( 'blog-' . $blog->userblog_id.'-c' );
    }
}
add_action( 'admin_bar_menu', 'remove_sites_edit_comments', 999 );

Recommended site search: domain name registration query cloud server vps, European server and American server, domain name space purchase private server rental, virtual host space, registration-free virtual space free server Chinese mainland cloud host, server,

WordPress removes the specified items in the

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码