login - Different homepage for logged in users

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 th

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 !

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742278902a4414118.html

相关推荐

  • login - Different homepage for logged in users

    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 th

    22小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信