117 Responses

  1. Thomas Clausen
    Thomas Clausen Published |

    This is brilliant Justin, thanks for sharing this.

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

    1. Sarah M.
      Sarah M. Published |

      I have to thanks this tutorial too.

      Big Thanks.

  2. Ryan
    Ryan Published |

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

  3. Many
    Many Published |

    I’ve really said it but surely shortcodes are lovely 😀

  4. Nice
    Nice Published |
  5. The Frosty @WPCult
    The Frosty @WPCult Published |

    Wow I can see how this could be useful.

  6. Dick
    Dick Published |

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

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

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

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

    Justin, you da man!!!!

  13. 10 incredibly cool WordPress shortcodes
  14. Jason
    Jason Published |

    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

  15. Ditutu
    Ditutu Published |

    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 .

  16. WPSavetnik - Zaštita sadržaja lozinkom
  17. Developing a user management plugin
  18. Ralf Skirr
    Ralf Skirr Published |

    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?


  19. Ralf Skirr
    Ralf Skirr Published |

    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.

  20. WordPress tips, hacks and tutorials » Nice2All.com » Content for Logged-In Users Only
  21. Lynne
    Lynne Published |

    The members only code snippet worked beautifully. Thanks.

  22. Lynne
    Lynne Published |

    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.

  23. Lynne
    Lynne Published |

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

  24. CG
    CG Published |

    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.

  25. John
    John Published |

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

  26. Coafuri
    Coafuri Published |

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

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

    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?

  33. Enhance Your WordPress Themes With Shortcodes | Devlounge
  34. Luis Lopez Garay
    Luis Lopez Garay Published |

    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.

  35. Sincere
    Sincere Published |

    I Love this post 😛 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 😛

  36. 37 Cool Wordpress Hacks And Tutorials You Should Try |
  37. 37个Wordpress经典教程 | 尚7科技
    37个Wordpress经典教程 | 尚7科技 at |
  38. 37个Wordpress经典教程 | 第七日
    37个Wordpress经典教程 | 第七日 at |
  39. PHP-help » 22 Latest Exceptional WordPress Hacks
  40. Occasio
    Occasio Published |

    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.

  41. jane
    jane Published |


    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 ?

  42. stonecoldcnc
    stonecoldcnc Published |

    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?

    [theme-my-login before_widget="" after_widget="" show_title="0" instance="tml-page"]
    any other content
  43. 7 Very Handy Shortcodes for WordPress | Devlounge
  44. sagive
    sagive Published |

    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 🙂

  45. Ryan
    Ryan Published |

    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.

  46. Rohan
    Rohan Published |

    Nice idea, comes very handy at times.

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

  47. Enrico
    Enrico Published |

    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

  48. Enrico
    Enrico Published |

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

    return $content;

    return do_shortcode($content);

    I hope could be useful for others!

    1. khalid
      khalid Published |

      U r awesome. Do you know that 😉

  49. Jon
    Jon Published |

    Not cool —

    Link removed by the administrator.

  50. dave
    dave Published |

    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!

    1. khalid
      khalid Published |

      Agree.. This makes me feel like I’m at the top of the coding Pyramid

  51. Joakim Kristiansen
    Joakim Kristiansen Published |

    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?


  52. 22 Latest Exceptional WordPress Hacks | Tutorials | instantShift
  53. Agnel Waghela
    Agnel Waghela Published |

    Thanks for this great tutorial.

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

  54. S.K
    S.K Published |


    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.


  55. Cx Rana
    Cx Rana Published |

    great justin brother….i like ur every post.

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

    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?

  60. Rene
    Rene Published |

    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

  61. Ryu
    Ryu Published |

    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.

  62. SM
    SM Published |

    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?

  63. Jean
    Jean Published |

    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.

  64. 22 Latest Exceptional WordPress Hacks | Template joomla, wordpress premium free , ebook
  65. Michael
    Michael Published |

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

    Is there anyway to create a custom login page?

    Thanks in advance!


  66. Sahil Mepani
    Sahil Mepani Published |

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

  67. Jirka
    Jirka Published |

    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?

  68. Royce
    Royce Published |

    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?

    1. Ørjan
      Ørjan Published |

      Royce, are you by any chance also using the Members plugin (also by Justin Tadlock)?

      I had exactly the same problem, until I realized that the mentioned plugin also uses the same shortcode [access].

      If you are using it, try renaming the shortcode name [access] in your own function to something else like [has_access], it worked for me!

  69. David
    David Published |

    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…?

  70. Andres
    Andres Published |

    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;


    return do_shortcode($content);
  71. Shortcode for Members Only Content | Footscray Maker Lab
  72. Tracey
    Tracey Published |

    Thanks for this and for the guides and articles you have written for magazines. All been so helpful over the years 🙂

  73. Пишем плагин для WordPress | Код это поэзия.
  74. Membuat Kontent Artikel Khusus Hanya Untuk Members Pada WordPress
  75. Homar
    Homar Published |


    I was looking for a plugin, but found this and settled for it lol

    Works perfectly, thanks!

  76. Nathan
    Nathan Published |

    Very useful, even four years later. Thank you for this!

  77. Awesome Shortcodes For Your WordPress Blog | Welcome
  78. 22 Latest Exceptional WordPress Hacks | Brisk Blog
  79. loic
    loic Published |

    Very useful plugin.

    But I just notice that shortcode has a conflict with gallery shortcode. Actualli, it doest not display gallery but only the shortcode ([gallery columns="4" link="none" ids="265,268,599,598"]).

  80. Martin
    Martin Published |

    Hi, i love your solution, but i got one problem.

    i want to run another shortcode inside [member][shortcode][/member].

    For some reason, it works on posts, but not on pages.

    On pages I see the inner shortcode as plaintext?!

    I would be glad, if you could help me out

    Thanks in advance

  81. rahim
    rahim Published |

    Hi Guys,

    I am new to the world of wordpress shortcodes, I am trying to use this code snippet to hide some info to non-logged in users within a page/post and can not seem to get it working.

    the url where i am using the shortcode is: http://www.webtrendz.co.uk/client-demo/assist/services/

    i have added the php snippet into functions.php but for some reason its not converting the shortcode into a tag.

    i actually see the the shortcode in the browser like [member]rahim[\member]

    Please can someone put me in the right direction?

    sorry if this is a proper newby question.

    1. David
      David Published |

      make sure you’re logged out when viewing it.

  82. David
    David Published |

    This is great, thank you for posting this!!!!!!

  83. max
    max Published |

    hi Justin,

    i’m using your brilliant tips in conjuction with Shortcode Exec PHP to dislay content according to user status.

    the problem i’m having is that nesting other shortcodes within doesn’t work.

    this is the function (in Shortcode Exec PHP):

    if ( is_user_logged_in() && !is_null( $content ) )

    return $content;

    return ”;

    and this is what i’d put on a page:


    the content here


    this works just fine. but if i put:


    the content here



    the nested shortcode doesn’t get executed.

    is there a way to sort this out? do i have to parse $content in the function looking for shortcodes, perhaps? or is there an easy way to make the code recognise shortcodes?

  84. Salim
    Salim Published |

    Good work Justin. Thank you 🙂

  85. Hamza pk
    Hamza pk Published |

    Thanks a lot sir, i have reduced server load using short-code for login users…Thanks again.

  86. Manuel Costales
    Manuel Costales Published |

    The best guide ever!!!

    Thanks a lot!

  87. Srikanth S
    Srikanth S Published |

    Thanks Justin, It was really helpful.

  88. Andrei
    Andrei Published |

    Hello Justin!

    A very useful addon, indeed!

    Is there a way to integrate the shortcode in the template? I’m trying to use it in a front-end editor (to hide some fields from a category of members).

    thank you in advance!


    1. Andrei
      Andrei Published |

      PS: I’m not a coder…

  89. Display content for member's only using shortcode | rixv.net
  90. Wordpress - hcallens | Pearltrees
    Wordpress - hcallens | Pearltrees at |
  91. Paul
    Paul Published |

    Hi Justin – so this was obviously posted some years back but it looks like it might be what I’m after. In a nutshell, I have a contact form which allows users to upload a file. What I would like is to make users register and log in before uploading a file. I think the simplest way of doing this is making the entire page (with the contact form and upload button on it) members only accessible. Would your solution work for that?



  92. Matthew Jones
    Matthew Jones Published |

    I just used this on one of my clients websites for their My Account page. It is awesome when you google something and the first link you click on you find the perfect thing. Will be using it on more of our client websites and it saves having to install a plugin.

    I also dont mind giving donations if it saves time on our end.

  93. Matthew Jones
    Matthew Jones Published |

    Hey it is end of the day here, can you just edit my above post from person thing to perfect thing.

  94. chris
    chris Published |

    You are simply the best. this worked for me thanks

  95. Rubb
    Rubb Published |

    Great, was looking for something like this,

    found other that did not work, this one is working

  96. Toon
    Toon Published |

    Hi there,

    I’ve been searching all over the web for this, but how do I use these shortcodes in a php template?

    I want to use the [visitor] and [/visitor] shortcodes in my single.php but I can not figure out how to make it work.

  97. Daniel
    Daniel Published |

    This is great, but I was just wondering, if I want to do this by user instead of capability, how should I change the code? Thanks!

  98. Chris
    Chris Published |

    Thanks Justin – very helpful resource 🙂

  99. Richard Barker
    Richard Barker Published |

    Still a great article even though published 8 years ago! Just helped me out, cheers Justin.

  100. reza
    reza Published |


    Unfortunately it’s not workinf for anothe shortcode related to Subscribe & Download .

    when we put these codes we saee exactly as they are. What’s your offer


    [sdfile url=”http://yoursite.com/download/x.zip”]


    1. Will
      Will Published |

      Simply wrap $content with do_shortcode like this:

      return do_shortcode($content);

  101. james
    james Published |

    what a lifesaver <3 thank you so much, you are my virtual here <3

  102. Javi
    Javi Published |

    Hi Justin,

    Thank You for this great post, and of course for the codes.

    You are the only one who thought about a shortcode to display content only for visitor… genius!



  103. Magda
    Magda Published |


    I am completely new to WP, learning as a I go along in building my web site. I’m trying to set up a page which will play a YouTube free video for users that are not logged in. The same page in the same spot would also play a Vimeo full length video for users that are logged in (members). Basically I’d like the page to look identical before and after one logged in with the exception of different movie clip playing for users logged in.

    Someone told me this could be done with the code, I guess such as you mentioned in this article, however that this codes will disappear each time my version of WP will be updated. Is this correct? Thanks for any help and suggestions you could provide.

Comments are closed.