WordPress shortcode: Display content to registered users only


/ Published in: PHP
Save to your folder(s)

WordPress shortcode: Display content to registered users only


Copy this code and paste it in your HTML
  1. Just paste the following code on your functions.php file:
  2. add_shortcode( 'member', 'member_check_shortcode' );
  3.  
  4. function member_check_shortcode( $atts, $content = null ) {
  5. if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
  6. return $content;
  7. return '';
  8. }
  9. Once done, you can add the following to your posts to create a portion or text (or any other content) that will be only displayed to registered users:
  10. [member]
  11. This text will be only displayed to registered users.
  12. [/member]

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.