Site logo

Archived topic

Login sidebar

5 replies · Started by Fabian Cosmann on April 13, 2015

Viewing posts 1–6 of 6

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
Fabian

Hi 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 :)

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
Fabian

Are 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 :)

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

:(

Hmm, 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 :)

This archived topic is closed to new replies.