admin管理员组

文章数量:1332404

Hi I would love to show different content for logged in users and I don't want to use a redirect, I came up with this idea and it worked well but I am not sure if it is the right way

//Home.php file
If is_loggedin(){
get_header('login');
//My content
get_sidebar('login');
get_footer('login');
}
elseif (! is_loggedin()){
get_header();
//My content
get_sidebar();
get_footer();
}

I am using my own custom made theme, it worked fine but I want to know if it is advisable

Hi I would love to show different content for logged in users and I don't want to use a redirect, I came up with this idea and it worked well but I am not sure if it is the right way

//Home.php file
If is_loggedin(){
get_header('login');
//My content
get_sidebar('login');
get_footer('login');
}
elseif (! is_loggedin()){
get_header();
//My content
get_sidebar();
get_footer();
}

I am using my own custom made theme, it worked fine but I want to know if it is advisable

Share Improve this question asked Jul 9, 2020 at 14:03 Chigbata ChisomChigbata Chisom 111 bronze badge 1
  • That is not related to your question, by why using elseif (! is_loggedin()){ instead of else {? User can be logged in or not logged in, there are no third variant. – Ivan Shatsky Commented Jul 9, 2020 at 14:52
Add a comment  | 

1 Answer 1

Reset to default 1

What is the is_loggedin() function ? Is that something you have create by yourself ?

Wordpress already got what you need, : is_user_logged_in()

You can use is_home() & is_user_logged_in() to be sure that the content will not display on other page.

As @Ivan Shatsky say's, don't use "else condition" like that.

    //Home.php file
    if (is_home() && is_user_logged_in()) {
        get_header('login');
        //My content
        get_sidebar('login');
        get_footer('login');
    } else {
        get_header();
       //My content
       get_sidebar();
       get_footer();
    }

Not tested !

本文标签: loginDifferent homepage for logged in users