簡體   English   中英

被 wordpress 上的鈎子重定向時的消息

[英]Message when redirected by a hook on wordpress

我正在使用一個小代碼片段將未登錄的用戶從商店頁面重定向到主頁。

function my_redirect() {  
    //if you have the page id of landing. I would tell you to use if( is_page('page id here') instead
    //Don't redirect if user is logged in or user is trying to sign up or sign in
    if( !is_user_logged_in() && is_page('shop')){
        echo 'Non logged user - You are redirected to the main page'; 
        exit( wp_redirect( get_permalink(2604) ) );
    }
}
add_action( 'template_redirect', 'my_redirect' );

這工作正常。 但是我想提示一條消息說“您必須登錄才能訪問商店”。

我不知道該怎么做,我在代碼中的回顯沒有顯示任何內容。

任何的想法?

謝謝

你永遠不會看到 echo 的 output 因為這個動作是在 wordpress 決定加載哪個模板之前觸發的,所以它是一個無處不在的回聲(為什么 wp_redirect 在里面並退出 function?)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM