How To Add Custom Link In WordPress Admin Bar?

// Add Link In Admin Dashboard


add_action( 'admin_bar_menu', 'custom_wp_toolbar_link', 10 );

function custom_wp_toolbar_link( $wp_admin_bar ) {
    if( current_user_can( 'publish_posts' ) ){ // Set the permission level or capability here for which user tier can see the link.

        $args = array(
            'id' => 'james', // Set the ID of your custom link
            'title' => 'James\' Link', // Set the title of your link
            'href' => 'http://localhost/domhost/admin', // Define the destination of your link
            'meta' => array(
                'target' => '_self', // Change to _blank for launching in a new window
                'class' => 'Visit Site', // Add a class to your link
                'title' => 'James\' link to Star Wars' // Add a title to your link
            )
        );
        $wp_admin_bar->add_node($args);

    }
}


// Add Link In Admin Dashboard

Comments

Popular posts from this blog

Remove Add New Post Sub Menu From Custom Post

How To Remove and Add Visit Site Menu From WordPress Admin Bar?

Register Custom Post Type