Skip to content

Instantly share code, notes, and snippets.

@wp-user-manager
Last active November 16, 2022 21:29
Show Gist options
  • Save wp-user-manager/bb7c515fd25a158cfd9feefac47f45f5 to your computer and use it in GitHub Desktop.
Save wp-user-manager/bb7c515fd25a158cfd9feefac47f45f5 to your computer and use it in GitHub Desktop.
WP User Manager - Translate the profile URL slugs
<?php
function wpum_profile_tabs_translation_mapping() {
// Translated to Slovenian, change to your language
return array(
'about' => 'priblizno',
'posts' => 'objave',
'comments' => 'komentarj',
);
}
add_filter( 'wpum_get_registered_profile_tabs', function ( $tabs ) {
foreach ( wpum_profile_tabs_translation_mapping() as $tab => $translated_tab ) {
if ( ! isset( $tabs[ $tab ] ) ) {
continue;
}
$tabs[ $translated_tab ] = $tabs[ $tab ];
unset( $tabs[ $tab ] );
}
return $tabs;
} );
add_filter( 'wpum_get_template_part', function ( $parts ) {
$profile_tabs = wpum_profile_tabs_translation_mapping();
foreach ( $parts as $part ) {
foreach ( $profile_tabs as $tab => $translated_tab ) {
if ( false !== strpos( $part, $translated_tab ) ) {
$parts[] = str_replace( $translated_tab, $tab, $part );
}
}
}
return $parts;
} );
@wp-user-manager
Copy link
Author

Save this file to your /wp-content/mu-plugins/ directory (you might need to create the mu-plugins directory).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment