1

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

  • 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 Jul 9 at 14:52
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 !

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.