58 Responses

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

    This is brilliant Justin, thanks for sharing this.

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

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

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

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

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

  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 | | Reply

    Wow I can see how this could be useful.

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

    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.

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

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

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

    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

  9. bitkahuna
    bitkahuna May 31, 2009 at 12:44 pm | | Reply

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

    Justin, you da man!!!!

  10. Jason
    Jason July 9, 2009 at 1:11 am | | Reply

    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

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

    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 .

  12. Ralf Skirr
    Ralf Skirr August 2, 2009 at 8:36 am | | Reply

    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

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

    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/

  14. Lynne
    Lynne August 5, 2009 at 5:50 am | | Reply

    The members only code snippet worked beautifully. Thanks.

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

    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.

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

    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.”

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

    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.

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

    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!!

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

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

  20. mariusz
    mariusz December 11, 2009 at 6:33 am | | Reply

    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?

  21. Luis Lopez Garay
    Luis Lopez Garay December 12, 2009 at 11:55 pm | | Reply

    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.

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

    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

  23. 37个Wordpress经典教程 | 尚7科技 February 21, 2010 at 10:44 pm |
  24. 37个Wordpress经典教程 | 第七日 February 23, 2010 at 4:15 am |
  25. Occasio
    Occasio March 12, 2010 at 10:23 am | | Reply

    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.

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

    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 ?

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

    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]
  28. sagive
    sagive October 10, 2010 at 12:15 am | | Reply

    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 :)

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

    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.

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

    Nice idea, comes very handy at times.

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

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

    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

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

    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!

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

    Not cool —

    Link removed by the administrator.

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

    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!

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

    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

  36. Agnel Waghela
    Agnel Waghela November 8, 2011 at 4:27 am | | Reply

    Thanks for this great tutorial.

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

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

    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

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.