Question

Basically, I want to show non-logged in users a page that says 'register or log in.' But I want to show logged in users a standard homepage will all my posts.

Was it helpful?

Solution

Rarst's solution is indeed the simplest way to do it and the Members plugin also has heaps of other advantages.

You can also do it without a plugin, by using the is_user_logged_in() function

More info on http://codex.wordpress.org/Function_Reference/is_user_logged_in and http://codex.wordpress.org/Function_Reference/get_currentuserinfo#Parameters

OTHER TIPS

Home page only or whole site?.. I assume latter as it makes more sense.

The simplest way I know is to use Members plugin and enable Private Blog option it has.

If you're comfortable adding functions, this does the trick.

    /**
     * If a user is logged in, tell WordPress to use 'page' on front page of the site
     * @param string $value
     * @return string
     */
    function fn_set_page_as_front_for_loggedin_user( $value ) {
        if ( is_user_logged_in() ) {
            $value = 'page';
            //page is set as front page
        }
        return $value;
    }
    add_filter( 'pre_option_show_on_front', 'fn_set_page_as_front_for_loggedin_user' );

    /**
     * If user is not logged in, set our static page to act as home page
     * @param $value
     * @return int
     */
    function fn_set_context_based_page_on_front( $value ) {

        if( ! is_user_logged_in() ) {
            return $value;
        }

        //for logged in user, use page id - in this case 56
        return 56;
        //change with your own page id.
    }
  add_filter( 'pre_option_page_on_front', 'fn_set_context_based_page_on_front' );
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top