Back to Top

How do I add items in Top navigation bar?

wordpress dashboard

To add a node to a custom position in WordPress Toolbar is very easy and simple. In this article shows how to place menu item to top navigation in WordPress.

To add a new item into the WordPress Toolbar, you need to use admin_bar_menu action hook and to remove wp_before_admin_bar_render hook. you can use both hooks to add/remove items.

Let’s understand by code:

So, First, let’s see how to add custom node into admin bar.Below is add_action will add new node into top navigation bar in WordPress.

Read about: Disable Post Revisions in WordPress and File/Image Upload in WordPress

add_action( 'admin_bar_menu', 'custom_admin_bar_links', 25 );

function custom_admin_bar_links( $wp_admin_bar ) {
	if ( !is_user_logged_in() )
		return;

	$wp_admin_bar->add_node( array(
		'id'     => '’',
		'parent' => false,
		'meta' => array( 'class' => 'custom-node-class' ),
		'title'  =>  'Custom Node Title',
		'href'   => get_permalink()
	) );
}

Third parameter in add_action is priority value which defined position of menu item and function with the lowest priority number is executed first.

Now, Let’s see how to remove existing menu items from top navigation bar in WordPress.remove_node will remove items from top navigation bar.

add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );

function remove_admin_bar_links() {
global $wp_admin_bar;
	$wp_admin_bar->remove_node('wp-logo');// to remove wordpress logo
	$wp_admin_bar->remove_node('new-content');// To remove New post bar
}

That’ it.We’re Done! I’m hoping that you’ve found this article helpful.Before that I have written article about to show toolbar in WordPress.

As always, thanks for reading. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (2)

  1. How to show code in WP posts ?
    like below :

    add_action( ‘wp_before_admin_bar_render’, ‘remove_admin_bar_links’ );

    function remove_admin_bar_links() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_node(‘wp-logo’);// to remove wordpress logo
    $wp_admin_bar->remove_node(‘new-content’);// To remove New post bar
    }

    1. You can place code into your functions.php file.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to Get IP address in CodeIgniter

Posted on 6 years ago

Bhumi

What is JavaScript Hoisting

Posted on 3 years ago

Bhumi

How to use Interface in PHP

Posted on 7 years ago

Bhumi

Hello world

Updated 1 month ago

Nick Carter

In depth Understanding of Laravel Core

Updated 3 months ago

Bhumi

ECMAScript 6 New Features – 2

Updated 1 year ago

Bhumi

The Reader’s Poll – June 2015

Posted on 4 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 5 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 6 years ago

Bhumi