Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add an item to submenu of Activity

  • @deshmukh

    Participant

    I wanted to add a link to the submenu of Activity menu. Currently, the links are: Personal, Mentions, Favorites, Friends, Groups.

    I want to add another item — a link to site-wide activity.

    How to achieve it?

Viewing 3 replies - 1 through 3 (of 3 total)
  • @danbp

    Participant

    hi @deshmukh,

    add this to bp-custom.php

    function bpfr_custom_profile_sub_nav() {
    	global $bp;
    	$parent_slug = 'activity';
    		
    	//Add subnav item 	 
    	bp_core_new_subnav_item( array( 
    	'name'            => __( 'Go to Site Activity' ), 
    	'slug'            => $parent_slug, 
    	'parent_url'      => $bp->loggedin_user->domain . $parent_slug.'/', 
    	'parent_slug'     => $parent_slug, 
    	'screen_function' => 'bp_activity_screen_my_activity',
    	'position'        => 60,
    	'link'            => bp_get_activity_directory_permalink(),
    	) );
    }
    add_action( 'bp_setup_nav', 'bpfr_custom_profile_sub_nav' );

    Reference

    @deshmukh

    Participant

    @danbp

    This works great. Thanks.

    I could also change
    'link' => bp_get_activity_directory_permalink(),
    to
    'link' => 'http://google.com',

    and it worked as expected.

    I also tried my hand at bp_core_new_nav_item ('<li>https://codex.buddypress.org/developer/function-examples/core/bp_core_new_nav_item/</li>')

    But I am unable to add an arbitrary link to nav item. If I add a link declaration as in the case of sub nav. it gives out an error.

    Parse error: syntax error, unexpected ''link'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in /.../wp-content/themes/nu-white-child/functions.php on line 35

    Probably because the function does not expect a ‘link’ parameter.

    How do I add an arbitrary link to the nav item?

    @danbp

    Participant

    bp_core_new_nav_item doesn’t accept link or href parameters.
    And the slug use /bp_loggedin_user_domain/$slug/ so you can’t add directly an arbitrary link with this parameter.

    bp_core_new_nav_item and bp_core_new_subnav_item are respectively the buddy menu and the sub-menu, with each his own parameters. Same technique, but slightly different.

    But you can hook into the function to modify the slug array, like this:

    function bpfr_menubar_link() {
    	global $bp;
    
    	$bp->bp_nav[$slug] = array(
    			'name'     => 'My super link',
    			'slug'     => 'super_link',
    			'link'     => 'https://buddypress.org',
    			'css_id'   => 'super-link',	
    			'position' => 20
    		);
    }
    add_action( 'bp_core_new_nav_item', 'bpfr_menubar_link', 999 );

    Be aware that this nav menu is always user dependant, meaning that you will only see that link when you’re on your profile page. It won’t show when you’re on another members profile or not logged in. 😉

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add an item to submenu of Activity’ is closed to new replies.
Skip to toolbar