Oxygen Templates List in WP-Admin top bar

Marko Krstić
27 May 2021

Accessing Oxygens Builder templates list always needs several clicks. WordPress Admin top bar is always there and easily accessible.

If you don’t have too many things in the top bar this code will be perfect for you.

With this code, you will get an entire list of your Oxygen templates. No styling is required as you will get WordPress native admin bar styling by default.

<?php
/*
** Add Dropdown Custom Links to WordPress Admin Bar
*/

// Add Parent Link
function dplugins_toolbar_links($wp_admin_bar) {
    $parent_menu_args = array(
        'id' => 'dplugins-ct-templates',
        'title' => 'Oxygen Templates',
        'href' => site_url().'/wp-admin/edit.php?post_type=ct_template',
        'meta' => array(
            'class' => 'dplugins-ct-templates',
            'title' => 'Oxygen Templates'
        )
    );
    $wp_admin_bar->add_node($parent_menu_args);

    // Add Oxygen templates
    $ct_templates = get_posts(array(
        'post_type' => 'ct_template',
        'posts_per_page' => -1,
    ));
    if($ct_templates){
        foreach($ct_templates as $ct_template){
            $ct_template_args = array(
                'id' => 'dplugins-'.$ct_template->post_name,
                'title' => $ct_template->post_title,
                'href' => site_url().'/wp-admin/post.php?post='.$ct_template->ID.'&action=edit',
                'parent' => 'dplugins-ct-templates',
                'meta' => array(
                    'class' => 'dplugins-oxy-templates',
                    'title' => $ct_template->post_title,
                )
            );
            $wp_admin_bar->add_node($ct_template_args);
        }
    }
}

add_action('admin_bar_menu', 'dplugins_toolbar_links', 999);

?>

Scripts Organizer Settings

Trigger Location: Everywhere
Script Location: PHP

screenshot 2021 04 15 at 21.29.12 1

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy