Skip to:
Content
Pages
Categories
Search
Top
Bottom

Permalink structure

  • @kostritsaalex

    Participant

    Hey guys,

    How to replace the permalink structure from:
    {domain}{forum-slug}{usernicename}

    To:
    {domain}{forum-slug}{First_name-Last_name}

    Here is my code snippet hat change the structure of Permalink, but I am getting 404

    function custom_bbp_get_user_profile_url( $url, $user_id, $user_nicename ) {
    	// Get the user data
    	$user_info = get_userdata( $user_id );
    
    	// Check if user info is available
    	if ( $user_info ) {
    		// Get first name and last name
    		$first_name = isset( $user_info->first_name ) ? $user_info->first_name : '';
    		$last_name = isset( $user_info->last_name ) ? $user_info->last_name : '';
    
    		// Create custom user_nicename as "First Last"
    		$custom_nicename = trim( $first_name . ' ' . $last_name );
    
    		// Return the URL with updated user_nicename
    		return str_replace( $user_nicename, sanitize_title($custom_nicename), $url );
    	}
    
    	// If user info is not available, return the original URL
    	return $url;
    }
    
    // Hook the function into the filter
    add_filter( 'bbp_get_user_profile_url', 'custom_bbp_get_user_profile_url', 10, 3 );
  • You must be logged in to reply to this topic.
Skip to toolbar