74 Responses

  1. Thomas Clausen
    Thomas Clausen May 10, 2009 at 2:38 am |

    This is brilliant Justin, thanks for sharing this.

    You write it’s for post and pages, but would it work for widgets as well?

    Reply
  2. Ryan
    Ryan May 10, 2009 at 5:13 am |

    Great tutorial Justin. Thanks a bunch for all your contributions. Keep ‘em coming.

    Reply
  3. Many
    Many May 10, 2009 at 3:34 pm |

    I’ve really said it but surely shortcodes are lovely :D

    Reply
  4. Nice
    Nice May 10, 2009 at 4:57 pm |
    Reply
  5. The Frosty @WPCult
    The Frosty @WPCult May 10, 2009 at 9:19 pm |

    Wow I can see how this could be useful.

    Reply
  6. Dick
    Dick May 11, 2009 at 9:33 am |

    This is GREAT, but will you write a followup on how to facilitate the user signup or point me to a good source for that? Thanks.

    Reply
  7. Kevin
    Kevin May 11, 2009 at 4:38 pm |

    I really like not having to depend on plugins. Thanks for posting this. I’m going to start using it right away.

    Reply
  8. Kat
    Kat May 12, 2009 at 10:00 pm |

    Hi Justin,

    Love this info – thanks so much.

    Inferring that you’re not planning on doing a tutorial on the member-joining part of this process, can you suggest a resource for that code?

    Thanks again,

    - Kat

    Reply
  9. Using WordPress as a members website « Logorrhea
  10. Using shortcodes to show members-only content — WPCult
  11. WordPress shortcode: Display content to registered users only- Pro Blog Tutorials
  12. bitkahuna
    bitkahuna May 31, 2009 at 12:44 pm |

    Dick – I use sidebar login and register plus plugins to allow users to register as ‘subscribers’ only. Works great.

    Justin, you da man!!!!

    Reply
  13. 10 incredibly cool WordPress shortcodes
  14. Jason
    Jason July 9, 2009 at 1:11 am |

    I must be putting the code in the functions.php in the wrong place? I got it to hide content, but when a user goes to login there is an error:
    Warning: Cannot modify header information – headers already sent by (output started at /home1/capeknin/public_html/capek9cardio/wp-content/themes/CoolWater/functions.php:32) in /home1/capeknin/public_html/capek9cardio/wp-login.php on line 287

    Warning: Cannot modify header information – headers already sent by (output started at /home1/capeknin/public_html/capek9cardio/wp-content/themes/CoolWater/functions.php:32) in /home1/capeknin/public_html/capek9cardio/wp-login.php on line 299

    Reply
  15. Ditutu
    Ditutu July 16, 2009 at 1:25 pm |

    Great tutorial Justin , you are a great blogger . I’ve seen a lot of good posts wroted by you ,it’s impressive what you can do .

    Reply
  16. WPSavetnik - Zaštita sadržaja lozinkom
  17. Developing a user management plugin
  18. Ralf Skirr
    Ralf Skirr August 2, 2009 at 8:36 am |

    Hi Justin,

    That’s an elegant solution, better than using plugins with huge overhead.

    Unfortunately I get the ‘Cannot modify header information’ error too.

    Any suggestion how to fix it?

    Thanks,
    Ralf

    Reply
  19. Ralf Skirr
    Ralf Skirr August 4, 2009 at 12:02 am |

    Okay, I fixed the ‘Cannot modify header information’ error. For anybody who might have the same problem:

    Make sure there is no white space outside of the php start and end tags. While a blank line before the <?php start tag may look innocent, when processed by PHP, it will turn into an echo statement printing out a blank line. This is a common culprit.
    source:
    http://www.tech-recipes.com/rx/1489/solve-php-error-cannot-modify-header-information-headers-already-sent/

    Reply
  20. WordPress tips, hacks and tutorials » Nice2All.com » Content for Logged-In Users Only
  21. Lynne
    Lynne August 5, 2009 at 5:50 am |

    The members only code snippet worked beautifully. Thanks.

    Reply
  22. Lynne
    Lynne August 5, 2009 at 6:09 am |

    Interestingly if I use in a document, the members only code doesn’t work any more.

    Does anyone know if there’s a “fix” for this.

    Reply
  23. Lynne
    Lynne August 5, 2009 at 7:47 am |

    Interestingly if I use “nextpage” in a document, the members only code doesn’t work any more.

    Does anyone know if there’s a “fix” for this.

    “Sorry for doubleposting, but the code for nextpage that I inserted didn’t show up.”

    Reply
  24. CG
    CG August 26, 2009 at 1:22 am |

    i’d like to see this with a little button on the wysiwyg editor so that I can highlight my posts’s text that i want hidden… much like i would to bold some text etc.

    Reply
  25. John
    John September 1, 2009 at 12:22 am |

    Is there any way I can get this to work with post excerpts?

    Right now, if a post is within the [member] tags, nothing shows up in the excerpts. I’d like it to say something like “This post is viewable to members only”. Love the tip on the shortcodes!!

    Reply
  26. Coafuri
    Coafuri September 18, 2009 at 7:13 am |

    Hey, thanks for the code, I will just try this out.Definitely will be a great timesaver

    Reply
  27. 10 Useful WordPress Coding Techniques « Smashing Magazine
  28. Wordpress Blog Services - 10 Useful WordPress Coding Techniques
  29. 10 Useful WordPress Coding Techniques « Tech7.Net
  30. Web Design News » 10 Useful WordPress Coding Techniques
  31. 22 Latest Exceptional WordPress Hacks | EzTips | Wordpress Tips - Tutorials - Make Money Online
  32. mariusz
    mariusz December 11, 2009 at 6:33 am |

    Fine, but if in content section you’d find a link to file?

    It would be accessfull for non-logged users if they knew the link to a file… how to solve that?

    Reply
  33. Enhance Your WordPress Themes With Shortcodes | Devlounge
  34. Luis Lopez Garay
    Luis Lopez Garay December 12, 2009 at 11:55 pm |

    That was just as usefull as I need. Some people needs to hide content to their guest visitors and this post is the solution I give to somebody who asks me that.

    Reply
  35. Sincere
    Sincere December 28, 2009 at 7:30 am |

    I Love this post :P I was looking everywhere for this! But im having a problem, or maybe im doing it wrong…

    I did everything you described above, but when i view my page it shows the members tags [ ] in the brackets…and content is still visible. Imm working in wpmu/ BP does it still operate in mu nad bp? I assume it still would

    Any help would be greatly appreciated :P

    Reply
  36. 37 Cool Wordpress Hacks And Tutorials You Should Try |
  37. 37个Wordpress经典教程 | 尚7科技
    37个Wordpress经典教程 | 尚7科技 February 21, 2010 at 10:44 pm |
  38. 37个Wordpress经典教程 | 第七日
    37个Wordpress经典教程 | 第七日 February 23, 2010 at 4:15 am |
  39. PHP-help » 22 Latest Exceptional WordPress Hacks
  40. Occasio
    Occasio March 12, 2010 at 10:23 am |

    Wow this is going to allow me to completely redo my members section. I had been using forums as my member restricted section, this will be much better.

    Reply
  41. jane
    jane July 24, 2010 at 3:02 pm |

    hi

    can anyone let me know what code above i can use to hide specific contet if user logged in (loged in form) but another of user is logged in (hidden text)

    let say following senario:
    I have a chunk of text i want to hide, in its place i want to show log in form
    when user have logged in i want the form to be hidden and the chunk of text that were hidden to be shown

    any idea ?

    Reply
  42. stonecoldcnc
    stonecoldcnc July 31, 2010 at 7:24 am |

    Hi Justin

    I’m using the Mystique Theme which contains your member shortcodes. Everything works ok and the code is an exact copy as above. I have only one little problem, I’m trying to run another shortcode inside yours which does not seem to work. Is that possible at all and if so, how?

    [visitor]
    [theme-my-login before_widget="" after_widget="" show_title="0" instance="tml-page"]
     [/visitor]
    
    [member]
    any other content
    [/member]
    Reply
  43. 7 Very Handy Shortcodes for WordPress | Devlounge
  44. sagive
    sagive October 10, 2010 at 12:15 am |

    hey man.. thanks a lot!
    but can you help me a bit more?

    i want to show the shortcodes in a private page
    to the website owner and what ever i do
    to display the shortcode as a user manul failes

    no matter if i wrap it in or
    the actuall result of the shortcode apears
    instead of the explenation how to..

    how do you show [shortcode] without it actually
    activating the code? much like you did here

    p.s you should realy add a “notify me on new comments”
    so it would be easier to return to the page when respond published :)

    Reply
  45. Ryan
    Ryan October 29, 2010 at 5:56 am |

    Justin, this code is just the best, thanks for sharing.

    I have now setup some roles, added the shortcode to my template, and now have a widget area only for members who are agents.

    Such a clean and simple solution.

    You’re an absolute legend, thanks for sharing.

    Reply
  46. Rohan
    Rohan November 8, 2010 at 10:59 am |

    Nice idea, comes very handy at times.

    Do you have any idea for displaying certain widgets to logged in members only?

    Reply
  47. Enrico
    Enrico March 20, 2011 at 11:16 am |

    Hi Justin, thanks for your great job.
    I found this old article that is very good for me.
    Only a question: is there a way to insert a shortcode (for example a form made by cforms or gravity) into the [member] shortcode? I tried by myself but it doesn’t work, wp prints the shortcode as is and not the form.

    Thank you very much
    Enrico

    Reply
  48. Enrico
    Enrico March 21, 2011 at 6:29 pm |

    Solved! I am not a programmer, but it seems to work.

    Changed:
    return $content;

    with:
    return do_shortcode($content);

    I hope could be useful for others!

    Reply
  49. Jon
    Jon June 1, 2011 at 5:43 pm |

    Not cool —

    Link removed by the administrator.

    Reply
  50. dave
    dave June 2, 2011 at 3:38 am |

    Ian you just made me look like a coding god whilst on the phone to a client… searched for a solution to showing member content, cut and pasted your code into my functions.php, stuck the shortcode around a cform and hey presto… it worked. all in about 60 seconds. many thanks!

    Reply
  51. Joakim Kristiansen
    Joakim Kristiansen June 15, 2011 at 10:12 am |

    Thanks for the great tip Justin.

    It works great, but like stonecoldcnc above, I can’t get the Gravity Forms shortcode to work. Do you know a simple way to fix this?

    Thank,
    Joakim

    Reply
  52. 22 Latest Exceptional WordPress Hacks | Tutorials | instantShift
  53. Agnel Waghela
    Agnel Waghela November 8, 2011 at 4:27 am |

    Thanks for this great tutorial.

    It has been very help full for me.
    Thanks a lot.

    Reply
  54. S.K
    S.K November 10, 2011 at 11:51 am |

    Hi

    Excellent article.
    But to my horror, I find that your post’s content has been verbatim scraped and plagiarized in another blog where I landed after a search for the relevant keywords. I do not want to provide a direct link to the web page to avoid directing traffic to that site unwittingly! It is livexp dot net and the title is exactly this post’s title.
    Regards

    S.K

    Reply
  55. Cx Rana
    Cx Rana February 8, 2012 at 2:49 am |

    great justin brother….i like ur every post.

    Reply
  56. 10 awesomely cool WordPress shortcodes! | Techewire
  57. 10 Awesome Shortcodes For Your WordPress Blog
  58. Code snipits to help ‘CMS’ your WordPress sites › Gold Coast Web Design › WordPress support and hosting › THRIVE
  59. azimmo
    azimmo May 12, 2012 at 9:38 am |

    Perfect, but, i don’t uderstand why this text that appear for non registered users (This is members-only content.) have the pre and code tag HTML?

    Reply
  60. Rene
    Rene May 20, 2012 at 9:14 am |

    Great! I have searched long after how it was possible. Have taken it in use and it works well.

    However, a small problem turned out

    On the pages I use the code I can not use other [code] of any kind. for example. [content mirror site = undefined record type = page item = 138]

    The code is seen simply as plain text on the sides, and not the expected function

    Do you have a solution to this

    Reply
  61. Ryu
    Ryu August 2, 2012 at 6:30 pm |

    Hi Justin,

    I was trying to make a shortcode that displays user profile information. I followed your tutorial on creating custom fields in user profile. I wanted to know how to display such custom themes inside the shortcode so they can be placed for memberonly content page.

    Your help will be much appreciated.

    Reply
  62. SM
    SM August 13, 2012 at 9:45 am |

    Hi Justin, this is a great little shortcode, but for some reason, content within the [member] tags is showing up in the excerpts of my search results.

    If you check my site here: http://www.emaginetestbed.com/oicci/page/1/?s=Invest

    the posts with telephone numbers and addresses should all be hidden to non-members. On the actual page where this info is placed, the content within those tags is hidden.

    Any idea why this should happen and how I can fix it?

    Reply
  63. Jean
    Jean September 26, 2012 at 10:27 am |

    For the “[member]” function, it would be great if we could set an optional custom message for visitors who are not logged in. So – there can be a default message, but anywhere you want to customize the message for that page/content, you can.

    Reply
  64. 22 Latest Exceptional WordPress Hacks | Template joomla, wordpress premium free , ebook
  65. Michael
    Michael November 15, 2012 at 11:09 pm |

    Thank you for this information however, I do have a question.

    Is there anyway to create a custom login page?

    Thanks in advance!

    Michael

    Reply
  66. Sahil Mepani
    Sahil Mepani April 2, 2013 at 3:48 am |

    You just saved me couple of hours. Thanks a lot. Justin you ROCK

    Reply
  67. Jirka
    Jirka April 12, 2013 at 4:44 pm |

    Hi. I have a problem with shortcodes.
    I need put one shortcode ([contact form]) in to second shortcode ([member]).

    In oder words, i need only registered users can show contact form.
    Is it possible?

    Reply
  68. Royce
    Royce April 13, 2013 at 11:00 pm |

    Hi, this is great shortcode! One part I cannot seem to get to work is:

    return ‘Sorry, but you cannot access this content without…’;

    It shows nothing. Any ideas?

    Reply
  69. David
    David May 9, 2013 at 5:19 pm |

    Fabulous…is it possible to add check boxes to select and toggle several separate elements of content so only those check boxes selected show only their corresponding content elements…?

    Reply
  70. Andres
    Andres May 9, 2013 at 7:15 pm |

    Great shortcode! For those of you who like me where wondering how to make the code work with a shortcode inside of it. Its really simple just change.

    return $content;

    to

    return do_shortcode($content);
    Reply

Leave a Reply

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution.

Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.