WordPress:如何每次將特定用戶重定向到特定頁面? 這與登錄後無關
問題描述:
I use WordPress.
I know how to redirect a user to a specific page after logging in. But let\'s say they have already logged-in and they click specific URL, they should be redirected to another.
Sample:
usernameA The user has already logged-in. He clicks domainname.com/my-account He will be redirected to domainname.com/pageA
usernameB The user has already logged-in. He clicks domainname.com/my-account He will be redirected to domainname.com/pageB
All of them click the domainname.com/my-account but they have to be redirected to a different page.
This redirection is per user. Is there a way to do this in function.php?
圖片轉代碼服務由CSDN問答提供
感謝您的意見,我們儘快改進~
功能建議
我使用WordPress。</ p>
我知道如何將用戶重定向到 登錄後的特定頁面。但是假設他們已經登錄並且他們點擊了特定的URL,他們應該被重定向到另一個。</ p>
示例:
usernameA用戶已經登錄 。 他點擊domainname.com/my-account他將被重定向到domainname.com/pageA
usernameB用戶已經登錄。 他點擊domainname.com/my-account他將被重定向到domainname.com/pageB
nn
他們中的所有人都會點擊domainname.com/my-account但他們必須重定向到 不同的頁面。</ p>
此重定向是每個用戶。 有沒有辦法在function.php中執行此操作?</ p>
</ div>
網友觀點:
You can use the built-in wp_redirect() function. Use a hook where there has been no output yet but wordpress already has the necessary info, like the requested post_id. you can stick something like this in your functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
function myredirect() { $page_id = get_queried_object_id(); //im working with the id\'s here, but for better readability you can also work with slugs. //you shouldnt use the whole url, because it will mean trouble when changing/moving domain-names // //check if it\'s the page you want to redirect from. if($page_id==138) { $user_id=get_current_user_id(); $redirect_to=\'\'; switch($user_id) { case 1: $redirect_to=54840; break; } if(!empty($redirect_to)) { wp_redirect(get_permalink($redirect_to)); exit; } } } add_action(\'template_redirect\', \'myredirect\'); |
1. 帶 [親測] 說明源碼已經被站長親測過!
2. 下載後的源碼請在24小時內刪除,僅供學慣用途!
3. 分享目的僅供大家學習和交流,請不要用於商業用途!
4. 本站資源售價只是贊助,收取費用僅維持本站的日常運營所需!
5. 本站所有資源來源於站長上傳和網路,如有侵權請郵件聯繫站長!
6. 沒帶 [親測] 代表站長時間緊促,站長會保持每天更新 [親測] 源碼 !
7. 盜版ripro用戶購買ripro美化無擔保,若設置不成功/不生效我們不支持退款!
8. 本站提供的源碼、模板、插件等等其他資源,都不包含技術服務請大家諒解!
9. 如果你也有好源碼或者教程,可以到審核區發布,分享有金幣獎勵和額外收入!
10.如果您購買了某個產品,而我們還沒來得及更新,請聯繫站長或留言催更,謝謝理解 !
GG資源網 » WordPress:如何每次將特定用戶重定向到特定頁面? 這與登錄後無關