Member only content

add_shortcode( 'member', 'member_check_shortcode' );

function member_check_shortcode( $atts, $content = null ) {
         if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
                return $content;
        return '';
}

Uses:

[member]
This text will be only displayed to registered users.
[/member]

Require login to view specifics posts in wordpress

function you_must_login() {
        global $post;
        if ( !is_single() ) // Use: !is_single() for members only posts and, Use:  !is_page() for members only pages.
        return;
        $post_ids = array( 188, 185, 171 ); // array of post IDs that force users to login before reading
        if ( in_array( (int) $post->ID, $post_ids ) && !is_user_logged_in() ) {
                auth_redirect();
        }
}
The following two tabs change content below.

Md Jahed

Latest posts by Md Jahed (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *