Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to re-order Messages subnav items (tabs)


  • maccast
    Participant

    @maccast

    I was looking for a simple way to re-order subnav items. In my case, on the Messages page. I did a lot of searching came up short on a simple definitive answer that did not hack the core. I was able to finally piece meal the answer together from old threads and thought it might be helpful to have the solution in a single place, so here goes.

    It’s basically the same technique as re-ordering the main nav items, but just one level deeper. I created this function and added it to my functions.php (really my custom plug-in in my case, but you get the idea).

    function add_reorder_messages_subnav_tab() {
        global $bp;
    
        //reorder messages tabs
        $bp->bp_options_nav['messages']['compose']['position'] = 10;
        $bp->bp_options_nav['messages']['inbox']['position'] = 11;
        $bp->bp_options_nav['messages']['starred']['position'] = 12;
    }
    
    add_action( 'bp_setup_nav', 'add_reorder_messages_subnav_tab', 100 );

    You just need to replace the messages part with the parent nav you want to work in, say settings.

    If you need to see the default order positions before you reorder them just dump the parent item like:

    var_dump($bp->bp_options_nav['messages']);

    Hope this helps.

Viewing 4 replies - 1 through 4 (of 4 total)

  • danbp
    Participant

    @danbp

    Hi @maccast,

    thank you for the tutorial and sharing your trick, but there is a little problem !

    bp_options_nav is deprecated since 2.6 – you can verify by enabling wp-debug in wp-config.php or by reading the doc.

    Get the right navigation solutions available for BP 2.6+ here:

    Navigation API


    maccast
    Participant

    @maccast

    Oh, sorry. I totally missed that. We’ll guess this still works for older versions. Thanks.


    maccast
    Participant

    @maccast

    Just so this is complete. Here’s the code updated for BuddyPress 2.6 or later.

    
    function add_settings_subnav_tab() {
    
        //reorder messages tabs
        buddypress()->members->nav->edit_nav( array(
            'position' => 10,
        ), 'compose', 'messages' );
    
        buddypress()->members->nav->edit_nav( array(
            'position' => 11,
        ), 'inbox', 'messages' );
    
        buddypress()->members->nav->edit_nav( array(
            'position' => 12,
        ), 'sentbox', 'messages' );
    
         buddypress()->members->nav->edit_nav( array(
            'position' => 20,
        ), 'starred', 'messages' );
    
    }
     
    add_action( 'bp_setup_nav', 'add_settings_subnav_tab', 100 );
    

    danbp
    Participant

    @danbp

    Gracias seƱor ! I changed the topic title by adding “Messages”, as your snippet related specifically to this component.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar