Add Dropdown Pages Links to WordPress Admin Bar

Marko Krstić
3 Nov 2021

With this script you will have quick access to all the pages right from WordPress Admin Bar

Scripts Organizer Settings

add dropdown pages links to wordpress admin bar

Code

<?php
/*
** Add Dropdown Pages Links to WordPress Admin Bar
*/
// Add Parent Link
function dplugins_toolbar_page_links($wp_admin_bar) {
    $parent_menu_args = array(
        'id' => 'dplugins-ct-pages',
        'title' => 'Pages List',
        'href' => site_url().'/wp-admin/edit.php?post_type=ct_template',
        'meta' => array(
            'class' => 'dplugins-ct-pages',
            'title' => 'Pages List'
        )
    );
    $wp_admin_bar->add_node($parent_menu_args);
    // Add Pages List
    $ct_pages = get_posts(array(
        'post_type' => 'page',
        'posts_per_page' => -1,
    ));
    if($ct_pages){
        foreach($ct_pages as $ct_page){
            $ct_page_args = array(
                'id' => 'dplugins-'.$ct_page->post_name,
                'title' => $ct_page->post_title,
                'href' => site_url().'/wp-admin/post.php?post='.$ct_page->ID.'&action=edit',
                'parent' => 'dplugins-ct-pages',
                'meta' => array(
                    'class' => 'dplugins-oxy-pages',
                    'title' => $ct_page->post_title,
                )
            );
            $wp_admin_bar->add_node($ct_page_args);
        }
    }
}
add_action('admin_bar_menu', 'dplugins_toolbar_page_links', 999);

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy