BuddyDev

Search

[Resolved] Dynamic Link In Menu

  • Participant
    Level: Enlightened
    Posts: 104
    Erich199 on #2372

    Hi Brajesh,

    I’m wondering if you had a tutorial somewhere or could point me in the right direction for this.

    I’ve created a link that requires some php code in my forums-loop.php file.

    <a href="<?php bbp_user_profile_url( bbp_get_current_user_id() ); ?>forums/subscriptions/#bbp-author-unread-topics">Unread posts</a>

    I’d like to add this link to my menu as a sub-menu item, but I’m not sure how I can accomplish this.

    I have a link titled “Forum” and I’d like this to be a submenu item of my “Forum” main menu item.

    Thanks as always for your help and the great community here!

  • Keymaster
    (BuddyDev Team)
    Posts: 19859
    Brajesh Singh on #2379

    Hi Erich,
    Though it is possible to filter nav menu and add Item, I will prefer another approach.

    I will create a page call it say “my-subscriptions” and then on “template_redirect” action check if the user is logged and is trying to visit this page redirect to the link you wanted to link earlier.

    Something like this

    
    
    add_action( 'template_redirect', 'buddydev_bbp_redirect_tosubscription_page' );
    
    function buddydev_bbp_redirect_tosubscription_page() {
    	
    	if( !  is_user_logged_in() || ! is_page( 'my-subscription') ) {
    		return ;
    	}
    	
    	$url = bbp_get_user_profile_url( get_current_user_id() ) . 'forums/subscriptions/#bbp-author-unread-topics';
    	
    	wp_safe_redirect( $url );
    	exit(0);
    	
    }
    
    

    Hope that helps.

  • Participant
    Level: Enlightened
    Posts: 104
    Erich199 on #2397

    Hi Brajesh,

    Thanks so much! This worked out perfectly.

You must be logged in to reply to this topic.

This topic is: resolved