permalinks structure
-
Hi guys,
I am trying to make some adjustments toward permalink structure, so it uses {users}{first_name-last_name} instead of {users}{nicename}. I think I found the right filter to adjust and here is my code:// Add this function to your theme's functions.php file or your plugin file.
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 );The structure of the URL got changed as expected, however I am getting 404 not found. I’ve re-saved permalinks to refresh the cache, but it didn’t help. Any ideas where to look?
Thanks!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘permalinks structure’ is closed to new replies.