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 |1 Answer
Reset to default 1What 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
elseif (! is_loggedin()){
instead ofelse {
? User can be logged in or not logged in, there are no third variant. – Ivan Shatsky Commented Jul 9, 2020 at 14:52