admin管理员组

文章数量:1122832

Is there any way to redirect /wp-admin/profile.php to /members/your-profile

I do not want members to go to the default wp-admin page but instead go to the custom members page.

I tried a redirect via a redirection app, but that didn't work.

Thanks!

Is there any way to redirect /wp-admin/profile.php to /members/your-profile

I do not want members to go to the default wp-admin page but instead go to the custom members page.

I tried a redirect via a redirection app, but that didn't work.

Thanks!

Share Improve this question asked Nov 1, 2023 at 20:01 IanIan 1
Add a comment  | 

2 Answers 2

Reset to default 0

You might be able to use the edit_profile_url filter:

add_filter( 'edit_profile_url, 'wpse419568_user_profile_redirect', 10, 3 );
/**
 * Filters the URL for the user profile.
 *
 * @param  string $url     The profile URL.
 * @param  int    $user_id The user ID.
 * @param  string $scheme  The URL scheme (eg http, https, login, etc.).
 * @return string          The filtered URL.
 */
function wpse419568_user_profile_redirect( $url, $user_id, $scheme ) {
    // Don't change the URL for admin users.
    if ( ! current_user_can( 'manage_options' ) ) {
        // Assumes that the profile URL uses the User ID. Adjust to suit
        // your site's use case.
        $url = '/members/profile/' . absint( $user_id ); 
    }
    return $url;
}

Note: This code is untested and comes with no guarantee it will work. It's meant as a starting point, not a finished solution. Test it on a disposable / test site first.

I gave up trying to do it with any functions in WordPress (version 6.6.2, October '24). The profile.php script merely sets IS_PROFILE_PAGE and transfers to user-edit.php which pretty much gets straight to work except for a check to current_user_can( 'edit_users' ) (bypassed if IS_PROFILE_PAGE is set)... no doesn't call any hooks/filters I could see (except if multisite there's an additional check for editing other users).

So I added this to .htaccess (Apache) just ahead of the # BEGIN WordPress section:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^wp-admin/profile\.php members [R,L]
</IfModule>

For your site, if it's still the same as your original question, I believe you'd just change members to members/your-profile. (See Apache ModRewrite's RewriteRule directive if you want to do anything fancier.)

本文标签: redirect wpadminprofilephp to membersyourprofile