WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Customize WP Admin Bar (3 posts)

  1. Angela
    Member
    Posted 2 years ago #

    Hi,

    I want to remove 2 items from the current WP admin bar, and add a sub-menu item to the my profile menu. Here is my code, and it doesn't work.

    function customize_admin_bar {
            global $wp_admin_bar;
            $wp_admin_bar->remove_menu('wp-logo');
            $wp_admin_bar->remove_menu('updates');
            $wp_admin_bar->add_menu(array(
                    'parent' => 'my-account',
                    'id' => 'support',
                    'title' => __('Support Center'),
                    'href' => "#")
            );
    }
    add_action( 'admin_bar_menu', 'customize_admin_bar' ); // I tried to user 'wp_before_admin_bar_render' instead of 'admin_bar_menu'

    I've searched every where, but it doesn't seem like WordPress has a codex page that provide the names of the menu items.

    Angela

  2. Angela
    Member
    Posted 2 years ago #

    Actually, I got it figured just now. The following seems to be the answer I need. Just in case anyone is having the same problem as I am, you need separate functions to remove and add menus, each using different action hook.

    function remove_admin_bar_links() {
        global $wp_admin_bar;
        $wp_admin_bar->remove_menu('wp-logo');
        $wp_admin_bar->remove_menu('updates');
    }
    add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );
    
    function add_admin_bar_links() {
        global $wp_admin_bar;
        $wp_admin_bar->add_menu(array(
            'parent' => 'my-account-with-avatar',
            'id' => 'sup',
            'title' => __('Support Center'),
            'href' => "http://hosting.centilin.com/support/")
        );
    }
    add_action('admin_bar_menu', 'add_admin_bar_links');

    Angela

  3. csm2012
    Member
    Posted 2 years ago #

    Hello Angela,

    Thank you for posting this code. I have been able to utilize it on my bbpress 2.1.1 site. I have been working on creating another version of your code to add a link in the admin drop-down bar to the bbpress favorites. I am stuck and have tried everything that I know. If you or anyone could give me some pointers I would greatly appreciate it. Below is the php code in the bbp-user-template.php file.

    I figured I could somehow merge the two codes to create the link. There is not a straite link because the favorites calls up the user id of the specific user.

    /** Favorites *****************************************************************/
    
    /**
     * Output the link to the user's favorites page (profile page)
     *
     * @since bbPress (r2652)
     *
     * @param int $user_id Optional. User id
     * @uses bbp_get_favorites_permalink() To get the favorites permalink
     */
    function bbp_favorites_permalink( $user_id = 0 ) {
    	echo bbp_get_favorites_permalink( $user_id );
    }
    	/**
    	 * Return the link to the user's favorites page (profile page)
    	 *
    	 * @since bbPress (r2652)
    	 *
    	 * @param int $user_id Optional. User id
    	 * @uses bbp_get_user_profile_url() To get the user profile url
    	 * @uses apply_filters() Calls 'bbp_get_favorites_permalink' with the
    	 *                        user profile url and user id
    	 * @return string Permanent link to user profile page
    	 */
    	function bbp_get_favorites_permalink( $user_id = 0 ) {
    		return apply_filters( 'bbp_get_favorites_permalink', bbp_get_user_profile_url( $user_id ), $user_id );
    	}

    Thank you,

    CSM2012

Topic Closed

This topic has been closed to new replies.

About this Topic