How to add submenu to WordPress admin panel

I need to add a drop-down menu in Wordpress in the admin panel to enable multiple links. What is the best solution?

+2
source share
1 answer

I was looking for an answer to this question for a while and could not find a solution here, so I thought it would help! I found a great blog post and a great solution to my question:

http://davidwalsh.name/add-submenu-wordpress-admin-bar

As adding functionality to your theme and other areas of administration, directives will appear in your theme functions.php file. The code itself should be self-evident:

function create_dwb_menu() {
    global $wp_admin_bar;

    $menu_id = 'dwb';
    $wp_admin_bar->add_menu(array('id' => $menu_id, 'title' => __('DWB'), 'href' => '/'));
    $wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => __('Homepage'), 'id' => 'dwb-home', 'href' => '/', 'meta' => array('target' => '_blank')));
    $wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => __('Drafts'), 'id' => 'dwb-drafts', 'href' => 'edit.php?post_status=draft&post_type=post'));
    $wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => __('Pending Comments'), 'id' => 'dwb-pending', 'href' => 'edit-comments.php?comment_status=moderated'));
}
add_action('admin_bar_menu', 'create_dwb_menu', 2000);

; . WordPress, !

+4

Source: https://habr.com/ru/post/1611298/


All Articles