I want different home page for logged user

Hello,

I want the non-logged-in users to see the normal home page and the logged-in users to see the buddypress activity page.

I was tried do this function with visual composer’s content type but there is too space area, also I think if both user see same page site will be slow ( I’m not sure but I think it is )

  • Adam Czajczyk
    • Support Gorilla

    Hello Variotik,

    I hope you’re well today and thank you for your question!

    The code that you posted in your last post would also do nothing else but just a redirect. I admit though that I’m not quite sure if there’s an easy to use solution for that. I think that a small “trick” could do the job but it would require you to:

    1. Set BP activity page as static homepage in WP settings first

    2. Then create your homepage as custom page template file entirely, meaning that even it’s content would be served directly from template.

    Then a code like this could be used as MU plugin:

    <?php
    function my_special_homepage() {
    if ( is_front_page() AND !is_user_logged_in()) {
    include( get_template_directory() . '/homepage.php' );
    exit;
    }
    }
    add_action('template_redirect', 'my_special_homepage');

    Best regards,

    Adam

  • Variotik
    • The Crimson Coder

    As far as I understand, I will set the bp activity page as the home page from the wp settings

    Then I will create a homepage.php file and put into it what I want it to appear on the main page

    But with this method I can not do exactly what I want because it can be very difficult to write homepage.php on my current main page (ie the home page that the uninitialized view will see), because it was done with theme widgets, visual composer and some visual composer add-ons

  • Variotik
    • The Crimson Coder

    <?php

    function my_special_homepage() {

    if ( is_front_page() AND !is_user_logged_in()) {

    include( get_template_directory() . ‘http://variotik.com/ana-sayfa/’ );

    exit;

    }

    }

    add_action(‘template_redirect’, ‘my_special_homepage’:wink:;

    I was change like php file like this maybe this way problem solve

    Do you have any idea about this problem?

    Thanks! =D

  • Adam Czajczyk
    • Support Gorilla

    Hello Variotik!

    The code from your previous post will not work properly. And yes, you are right that if you put the code as MU plugin that will affect entire network. I haven’t thought of that, I’m sorry. This can fortunately be fixed but if a solution with putting entire homepage content into the template file isn’t suitable for you, we need to find another way to do this. :slight_smile:

    That said, I think it would be best if you start with setting you site back to its original configuration – with regular homepage and no additional code.

    I noticed that you got Membership 2 Pro plugin installed on your site so what about a bit different way:

    – you could create an additional membership of type “Guest”, that membership includes automatically all the visitors to the site that are not logged in

    – another additional membership would be of type “Default”, that one includes automatically all the logged in users that are registered on the site but are not members of other memberships

    – use BuddyPress Activity Shortcode plugin and it will give you a shortcode that you might put on you homepage so it would display BP activity stream:

    https://wordpress.org/plugins/bp-activity-shortcode/

    – then use Membership 2 Pro shortcodes for that “guest type” membership to protect entire content of homepage except activity shortcode; this way it would only be available for not-logged in users

    – then use Membership 2 Pro “Shortcode Protection” built-in add-on to assign access to BP Activity Shortcode to all other memberships (via “Membership 2 -> Protection Rules -> Shortcodes” page).

    As a result that should work this way:

    – the homepage would physically be exactly the same and by default (so as a super admin you would see it) it would contain both your regular homepage content and BuddyPress Activity Stream

    – visitors (not logged in users) would only see regular homepage content but not Activity Stream

    – all other (logged in users, regardless whether they are members of any memberships or not) would see Activity Stream but not a regular content of hompeage.

    Would that work better for you?

    Best regards,

    Adam

  • Variotik
    • The Crimson Coder

    I installed it only look, I don’t use. Already membership 2 pro plugin is a different plugin, it helps to get paid.

    Think like facebook or twitter. If you not logged you look registration page but if you logged you look timeline. I want this.

  • Adam Czajczyk
    • Support Gorilla

    Hello Variotik!

    I understand the goal. Facebook or Twitter however, they don’t run on WordPress. Both these services use fully custom code and they were build that way. Here we need to find a way to achieve it with a different software base.

    The Membership 2 Pro idea seem quite easy to implement and should work. It wouldn’t interfere with the way you are using Membership 2 Pro.

    I’m thinking of yet another way though and that might be the closest one to what you wish to achieve. It’s a bit more complex though:

    1. Create a custom page template so it would carry the design of your current homepage; name the file “homepage-main.php”;

    2. Create another custom page template so it would carry the design of your members-only page; name the file “homepage-members.php”;

    3. Create a file in theme folder that wouldn’t include anything apart from this code:

    <?php
    /*
    Template Name: Special Homepage
    */
    if ( is_front_page() AND !is_user_logged_in()) {
    get_template_part( 'homepage' , 'main');
    }
    else {
    get_template_part('homepage', 'members');
    }

    and name that file just “homepage.php”

    4. In your WordPress backend create a new page (it can be empty) and assign the “Special Homepage” template to it.

    5. In your WP settings set this new page as your homepage

    6. Now comes the “tricky part”:

    – in both “homepage-main.php” and “homepage-members.php” there’ll be a WordPress loop

    – in both files you would need to add code that would make it read a defined page from database instead of fetching the current one so before the loop code you would need to add your own query , like that:

    $query = new WP_Query(array( 'page_id' = 7 ));

    where in “homepage-main.php” file the number 7 should be replaced with an ID of a page that should be served to not-logged in users as a hompage (the one that currently is your homepage) and in “homepage-members.php” that number should be replaced with an ID of a page currently used for BuddyPress activity.

    That all together would give you exactly the effect you need.

    Kind regards,

    Adam

  • Predrag Dubajic
    • Support

    Hi Variotik,

    When you are logged in there’s .logged-in class in body tag so you can use that to show/hide certain content.

    For example, if you want to hide element for logged in users but show it for visitors you can use something like this:

    .logged-in .element-for-visitor {
    display: none;
    }

    .element-for-visitor {
    display: block;
    }

    Or the other way around, if you want to hide it from visitor but show for logged in user then use something like this:

    .element-for-loggedin-user {
    display: none;
    }

    .logged-in .element-for-loggedin-user {
    display: block;
    }

    Best regards,

    Predrag

  • Predrag Dubajic
    • Support

    Hi Variotik,

    I must say I’m a bit confused now.

    Based on your above comments I thought that you were able to already setup your site so BP activity page is visible on homepage so now you only want to use CSS in order to hide it, but when I check your site there’s no activity on homepage so I don’t know what should I be hiding for logged out users?

    Have you considered leaving your home page as it is but then use redirect that applies only to logged in users so it redirects them from home page to activity page?

    Something like this should do the trick:

    add_action('wp_head','wpmy_redirect_logged_in_users_away_from_home');
    function wpmy_redirect_logged_in_users_away_from_home() {
    if( is_user_logged_in() && !is_super_admin() && ( is_home() || is_front_page() ) ) {
    wp_redirect('URL_TO_ACTIVITY_PAGE');
    exit;
    }
    }

    Just replace URL_TO_ACTIVITY_PAGE with URL to your activity page and note that this code will apply to logged in users except for super admin so you can still access homepage with your super admin account.

    This code should be added in a child theme that’s used only on main site so that code doesn’t redirect on other network subsites.

    Best regards,

    Predrag

  • Variotik
    • The Crimson Coder

    Already I don’t add buddypress activity row.

    I was try hide to logged user css code but its not work. If its work I will add buddypress activity row and problem solved.

    Yes I know it’s too confused but I already don’t want like this. But there is only one solution, so I have to do.

    I want two different home page for logged user and visitor but I think this is impossible, So I had to try such a complicated solution and add buddypress activity row to visitors homepage and set visibility

  • Predrag Dubajic
    • Support

    Hi Variotik,

    What exactly was the issue when using CSS I provided you above?

    Which element did you apply it to?

    I can’t give you exact CSS to hide activity section until is actually added on your site.

    Once it’s in place I can check it out and find the selector that we can use in order to hide only activity section and leave the others showing.

    If you could add BP activity to your home page and grant support access I’ll gladly check for the correct CSS code that you can use.

    Best regards,

    Predrag

  • Dimitris
    • Support Star

    Hey there Variotik,

    hope you're doing good today! :slight_smile:

    I can still see that you haven't added a activity stream in your homepage.

    You can do so using this little plugin: BuddyPress Sitewide Activity Widget

    https://wordpress.org/plugins/buddypress-sitewide-activity-widget/

    You could then add a new widget in your homepage to bring up the activity stream.

    It also provides a setting to hide it for non-logged in users, so you'll need no extra CSS rules for that. :wink:

    Warm regards,

    Dimitris

  • Predrag Dubajic
    • Support

    Hi Variotik,

    I’m afraid that this goes bit beyond scope of support we can offer here as this is custom development you’re looking for.

    Please double check Adam’s response and follow the instructions as you need to have 3 files for this solution.

    First one would be homepage.php with the above code and that would be your new home page, and from that file we will call new ones that will call your desired content.

    So next you need to create homepage-main.php file would be the content that will be loaded when visitors are looking at the home page.

    And last, you need homepage-members.php file that will hold the content for logged-in users.

    If you need help with completely coding these pages you can post a job in our job board where you can hire a developer to assist further:

    http://premium.wpmudev.org/wpmu-jobs/

    Please note that, no WPMU official staff members are allowed to work in the job board.

    Best regards,

    Predrag

  • Variotik
    • The Crimson Coder

    Now I create three page template and set to three page

    create a blank page for homepage.php

    buddypress activity page for homepage-members.php

    normal homepage for homepage-main.php

    homepage.php this

    <?php

    /*

    Template Name: Special Homepage

    */

    if ( is_front_page() AND !is_user_logged_in()) {

    get_template_part( ‘homepage’ , ‘main’:wink:;

    }

    else {

    get_template_part(‘homepage’, ‘members’:wink:;

    }

    homepage-members.php and homepage-main.php only repeat offical themes full width template

    But still not working

  • Predrag Dubajic
    • Support

    Hi Variotik,

    You need to have different content for those two pages, you can’t use default content for full width template.

    What the above code does is that it acts like a welcome code on homepage, it checks then if user is logged-in or not and based on that it calls different files.

    So in those files you need to set your homepage content in one file and buddypress activity page on other.

    You would need to have required code in each file for a specific page.

    Best regards,

    Predrag

  • Predrag Dubajic
    • Support

    Hi Variotik,

    I’m afraid that we can only offer support in English here.

    The task you’re looking for is not an easy one as it was mentioned before, you would need to do some extra coding to include your visitor homepage to homepage-main.php file and then add BP activity on homepage-members.php

    You can also check some suggestions here:

    https://stackoverflow.com/questions/20039607/different-wordpress-front-page-for-logged-out-and-logged-in-users

    https://wordpress.stackexchange.com/questions/225040/setting-a-specific-home-page-for-logged-in-users

    You may want to consider hiring a developer if you’re still going with two different templates solution for your site.

    Best regards,

    Predrag

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.