2017-06-20 55 views
0

我試圖阻止用戶在他們已經登錄時訪問頁面。任何人都請幫助我如何做到這一點。我檢查了谷歌和所有利益溢出,但沒有找到任何解決方案。希望很快得到答案。 謝謝如何在用戶登錄時停止訪問WordPress頁面

+0

可以如果有條件與is_user_logged_in功能https://developer.wordpress.org/reference/functions使/ is_user_logged_in/ –

+0

我想爲特定頁面而不是整個網站執行此操作 – johnsmith

+1

因此,如果條件是用戶登錄且頁面id = xxx,則只需添加。 –

回答

0

試試這段代碼,將它放在你的主題函數中。

function my_page_template_redirect() 
{ 
    if(is_page('page-slug') && is_user_logged_in()) 
    { 
     wp_redirect(home_url()); 
     exit(); 
    } 
} 
add_action('template_redirect', 'my_page_template_redirect'); 

根據您的情況更改頁面slu you,您也可以使用page_id檢查這些參考文件下面。不要忘了保存永久把這些代碼

參考後:

https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect https://developer.wordpress.org/reference/functions/is_page/

相關問題