- This topic has 5 replies, 2 voices, and was last updated 8 years, 5 months ago by
Tom.
-
AuthorPosts
-
April 13, 2015 at 4:37 am #98225
Fabian Cosmann
Hi Tom,
is there any possibility to show a page with login sidebar if not logged in and show page without sidebar (only content no sidebar) if logged in?
And vice versa for another page: if I’m not logged in and I go to the my account page, there is a form for login and register given, so it looks bad to show the sidebar login as well. Can I then hide it?Thanks
FabianApril 13, 2015 at 9:58 am #98294Tom
Lead DeveloperLead DeveloperHi Fabian,
How about removing the sidebar on the page that has the login form in the content?
You can also use a plugin like this to show/hide widgets depending on if the user is logged in or not: https://wordpress.org/plugins/display-widgets/
However, that will only work if the login widget isn’t the only widget in the sidebar.
If neither of the above work, you can use a function to set the sidebar layout depending on if the user is logged in or not.
Let me know π
April 13, 2015 at 1:17 pm #98339Fabian Cosmann
Hi Tom,
thank you for the quick answer. Unfortunately, this is not exactly what I’m looking for.
I would like to have a way to change flexible between the page properties full width (without sidebar) and content with right sidebar depending e.g. if a user is logged in or not.
In case the user is not logged in, I would like to show a sidebar with “login sidebar” and possibly other widgets and if the user is logged in I want to show another content on the page witch uses the whole wide of the page without a sidebar.
I would like to have a function in a template php-file.Thanks
FabianApril 13, 2015 at 7:12 pm #98372Tom
Lead DeveloperLead DeveloperAre you wanting to show different content on the page depending on if the user is logged in or not as well?
If so, have you looked into any membership plugins? Most of them allow you to redirect users who aren’t logged in to a separate page asking them to login.
If the user is logged in, they’re allowed to access the page without any redirection.
If the content is the same, and the only thing you’re changing is the sidebar, the function I’ll give you will do the trick.
Let me know π
April 13, 2015 at 9:42 pm #98381Fabian Cosmann
Hi Tom,
I will have a deeper look to the membership plugins.
I tried to build the redirect on my own with this code in a GP child theme template:
<?php
/*
Template Name: Some_example
*/
?>
<?php if (!is_user_logged_in())
{
header(“Location: my_own_login_page_with_sidebar”);
}
else
{
get_header();
//page code
get_footer();
}?>But I get an error message:
Cannot modify header information – headers already sent
π
April 14, 2015 at 9:40 am #98493Tom
Lead DeveloperLead DeveloperHmm, I would do something like this:
add_action('wp','generate_redirect_page'); function generate_redirect_page() { // Change page-slug to which page they land on if ( is_page('page-slug') ) { // If user is logged in if ( is_user_logged_in() ) { // Do nothing - allow access } else { // If they're not logged in, redirect them to yoursite.com/no-access $redirect = site_url() . '/no-access'; wp_redirect( $redirect ); exit; } } }
And I would add it using one of these methods: http://generatepress.com/knowledgebase/adding-php-functions/
Let me know π
-
AuthorPosts
- You must be logged in to reply to this topic.