设置带有条件的 PHP #Wordpress 永久链接

Set #Wordpress Permalink with PHP with Conditions

我想要完成的是为登录用户设置不同的 wordpress 永久链接 登录用户使用:/loggedin/%post_id%/%postname%/,其他用户使用/post/%post_id%/%postname%/

这是 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%/' );
}};

我在这里遗漏了什么,有人可以指出或解决这个问题吗?

您在 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%/' );
    }
}