Home / functions.php / Member only content
  • How to Member only content

    no thumbnail sorry: Member only content

    Adding this PHP code to the functions.php file of your wordpress theme will allow you to place content you only wish members to see within the members short code [member][/member].

    ( click code to copy )

    wordpress snippet : 

    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 '';
    ( click code to copy )

    wordpress snippet : 

    This text will be only displayed to registered users.

    ( WordPress codex functions, hooks, in this snippet. )

    register, is_user_logged_in, add_shortcode, _n, is_feed,
  • EarthShaver

    Sweet Snippet!!
    but leaving the space empty for non-member visitors would be too boring. how about inserting some text-message for non-member visitors, like “You must be logged in to view this content” or something like that?

    Oh, and thanks for the good work!!

    • just return something other within return ‘some text’; and not blank should do the trick.