2017-02-21 46 views
1

什麼即時試圖完成設定不同的wordpress固定鏈接爲登錄用戶 對於登錄的用戶使用:/loggedin/%post_id%/%postname%/和他人使用/post/%post_id%/%postname%/集#Wordpress永久使用PHP與條件

這裏是我試着PHP代碼但不起作用

add_action('init', 'smartest_set_permalinks'); 
function smartest_set_permalinks() { 
global $wp_rewrite; 
if(is_user_logged_in) { 
$wp_rewrite->set_permalink_structure('/loggedin/%post_id%/%postname%/'); 
} else { 
$wp_rewrite->set_permalink_structure('/post/%post_id%/%postname%/'); 
}}; 

我在這裏丟失的是什麼可以有人指出或解決這個問題?

+0

什麼樣的「不工作」?它只是不工作或拋出一些錯誤? –

+0

不工作,它總是使用/ logged / – Niresh

回答

1

您在is_user_logged_in後缺少'()'。 is_user_logged_in()是一個默認的wordpress函數。並不需要函數大括號中的分號。

add_action('init', 'smartest_set_permalinks'); 
function smartest_set_permalinks() { 
    global $wp_rewrite; 
    if(is_user_logged_in()) { 
     $wp_rewrite->set_permalink_structure('/loggedin/%post_id%/%postname%/'); 
    } else { 
     $wp_rewrite->set_permalink_structure('/post/%post_id%/%postname%/'); 
    } 
}