WordPress and buddypress programming

Creating Custom URL’s with BuddyPress

Viewing 0 reply threads
  • Author
    Posts
    • #3563
      Michael Mc
      Keymaster
      @mkmcst

      change http://www.examplesite.com/members/username/projects to http://www.example.com/projects/username

      function bp_projects_rewrite_bp_uri($path) {
          if(strpos($path, 'projects/') === 1 && strlen( $path) > 5 ) {
      
              //Find the position of the second '/' and add one to fix the start of the username.
              $members_start_pos = strpos( $path, '/', 2 ) +1;
      
              //Find the end point of the username
              $members_end_pos = strpos( $path, '/', $members_start_pos );
      
              //Strip the username out of the input URL
              $username = substr( $path, $members_start_pos, $members_end_pos - $members_start_pos );
      
              //Return the reconstructed URL, which BP will accet as a valid page.
              return 'members/'.$username.'/card/';
          }
      
          return $path;
      }
      
      add_filter('bp_uri', 'bp_projects_rewrite_bp_uri');
Viewing 0 reply threads
  • You must be logged in to reply to this topic.