WordPress Snippets at WPcustoms

Add your own links to the admin bar

This is a quick example how to add custom html links to your WordPress admin bar. Insert any url at ‘href’ or simply use the admin url parameters. the link attributes can be customized with the ‘meta’ value.

 * Snippet Name: Add your own links to the admin bar
 * Snippet URL: https://wpcustoms.net/snippets/add-your-own-links-to-the-admin-bar/
  function wpc_adminbar_custom_links() {
    global $wp_admin_bar;
    $wp_admin_bar->add_menu( array(
        'parent' => false, // use 'false' for a root menu, or pass the ID of the parent menu
        'id' => 'settings_general', // link ID, defaults to a sanitized title value
        'title' => __('General Options'), // link title
        'href' => admin_url( 'options-general.php'), // name of file
        'meta' => array( 'html' => '', 'class' => '', 'onclick' => '', 'target' => '', 'title' => '' )
add_action( 'wp_before_admin_bar_render', 'wpc_adminbar_custom_links' );