my code stock.com

Show Wordpress Admin Bar Nodes

Snippet options

Download: Download snippet as show-node-ids.php.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

<?php
/*
Plugin Name: Show Node Ids
Plugin URI:  https://codex.wordpress.org/Function_Reference/get_nodes#Display_all_Node_ID.27s_of_the_Current_Page_in_the_Toolbar
Description: Developer snippet so show admin bar nodes, taken from the WP Codex
Version:     0.1
Author:      Wordpress Codex Snippet
Author URI:  http://www.Wordpress.org/
License:     GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Domain Path: /languages
Text Domain: sni
*/

// use 'wp_before_admin_bar_render' hook to also get nodes produced by plugins.
add_action( 'wp_before_admin_bar_render', 'add_all_node_ids_to_toolbar' );

function add_all_node_ids_to_toolbar() {

    global $wp_admin_bar;
    $all_toolbar_nodes = $wp_admin_bar->get_nodes();

    if ( $all_toolbar_nodes ) {

        // add a top-level Toolbar item called "Node Id's" to the Toolbar
        $args = array(
            'id'    => 'node_ids',
            'title' => 'Node ID\'s'
        );
        $wp_admin_bar->add_node( $args );

        // add all current parent node id's to the top-level node.
        foreach ( $all_toolbar_nodes as $node  ) {
            if ( isset($node->parent) && $node->parent ) {

                $args = array(
                    'id'     => 'node_id_'.$node->id, // prefix id with "node_id_" to make it a unique id
                    'title'  => $node->id,
                    'parent' => 'node_ids'
                    // 'href' => $node->href,
                );
                // add parent node to node "node_ids"
                $wp_admin_bar->add_node($args);
            }
        }

        // add all current Toolbar items to their parent node or to the top-level node
        foreach ( $all_toolbar_nodes as $node ) {

            $args = array(
                'id'      => 'node_id_'.$node->id, // prefix id with "node_id_" to make it a unique id
                'title'   => $node->id,
                // 'href' => $node->href,
            );

            if ( isset($node->parent) && $node->parent ) {
                $args['parent'] = 'node_id_'.$node->parent;
            } else {
                $args['parent'] = 'node_ids';
            }

            $wp_admin_bar->add_node($args);
        }
    }
}
?>

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.