WordPress: Member Only Content

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

Copy this code and paste it in your HTML
  2. function member_check_shortcode($atts, $content = null) {
  3. if (is_user_logged_in() && !is_null($content) && !is_feed()) {
  4. return $content;
  5. } else {
  6. return 'Sorry, this part is only available to our members. Click here to become a member!';
  7. }
  9. add_shortcode('member', 'member_check_shortcode');
  11. //add the following to your posts to create a section or text (or any other content) that will be displayed only to registered users:
  13. [member]
  14. This text will be displayed only to registered users.
  15. [/member]

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.