Puddinq.com sharing knowledge

Member or visitor content

Member or visitor content

Decide who can see the content

The code on the below can be used to:

  • Show content only to members
    [member]visible by members[/member]
  • Sow content only to guests
    [visitor]visible by visitors[/visitor]

Place it in the funtions.php in your theme folder.

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

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

add_shortcode('member', 'member_check_shortcode');