BuddyDev

Set default landing tab for BuddyPress Activity directory

If you are interested in changing the default landing  tab( activity listing type ) for BuddyPress Activity directory, then you can do it easily. We are going to see it with an example where we will change the default landing tab from “All Members” activity to “My friends” activity.

All you need to do is put the following code in your bp-custom.php

Here is a screenshot of the default activity tab:-

And here is what the user sees when they visit the activity directory for the first time(after you use the previous code)

As you noticed, the default landing tab is set to “My friends ” and lists friends activity instead of the default “All members” activity.

Code Explanation:-

In the code we check if a user is logged in, the activity scope is not set and the current page is activity directory, then we set ‘friends’ as the default scope. It makes BuddyPress display friends activity on the default activity directory landing page instead of the All members activity. You can change the scope to any valid activity scope. The other available scopes are “groups” and “mentions”.

Please do note that the default scope is only set if it was not already set earlier. If you are testing the code and you had visited activity directory earlier and had clicked on one of the tabs, your activity-scope would be already set. The code will only work for you when you clear the cookies.

Have fun working with BuddyPress 🙂

 

8 Responses to Set default landing tab for BuddyPress Activity directory

  • Hello,

    Please can this code work with the buddypress follow plugin
    Thank you

    • Hi Tosin,
      It will work with any plugin that acts a tab on activity directory.

  • I also found out about this plugin https://fuc.wordpress.org/plugins/bp-whats-hot/

    Will your code adapt to this

  • Hi Brajesh,
    this code seems to work but does not really.
    Initially, although the default tab is hilighted as set in the code (changed), the displayed content corresponds to the original default tab. Only after re-clicking the changed default tab, the proper content is loaded. Apparently, this issue is related to the fact that switching between the tabs is performed by javascript (not page reload).

    • Thank you Stefan,
      I have just corrected the code. I had missed to add the last line(for current request keeping it in the cookie global).

      Please check and do let me know if that works. There is no need for clicking. It all works based on the cookie.

      Regards
      Brajesh

  • Many thanks, Brajesh, now it works as expected.
    In fact, I needed this for the BP Groups Directory to set “My Groups” as default tab. So I have modified your code:

    I do not check whether the cookie was already set because I want to land on the new default tab on every visit, regardless of any previous views.
    Regards,
    Stefan.

    • Thank you Stefan.
      Definitely helpful for people looking to change for groups. Appreciate you sharing here 🙂

      Thank you
      Brajesh

Leave a Reply

Are you looking for support?

Please ask support questions in BuddyDev Forum and help us serve you better. Please use comment for general discussion/feature suggestions.

Your email address will not be published. All the fields marked as * are required.

If you are posting code, please use <pre> { Your Code Block } </pre>. Example:- <pre> echo $name; </pre>

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">