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 12 Answers
Reset to default 0You 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
版权声明:本文标题:redirect wp-adminprofile.php to membersyour-profile 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736284988a1927363.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论