Both these code snippets allow you to hide posts from logged out users. The content will be hidden from all archive page types as well as single posts so the only way users can access the content is if they are a logged in user.
Based on the following question from a member :
I’m trying to hide a category from logged out users. I know I could use a plugin but was trying not to. If its quicker to use a plugin, let me know. Basically a client wants a staff only category for internal updates.
Both solutions use code and do not require the installation of a plugin :
Solution 1 : This method creates a shortcode which you can use to wrap any content you want hidden from logged out users.
Solution 2 : This method automatically hides all content assigned to 1 specific category from logged out users. No need to wrap content in shortcodes.
Both solutions display a link to a page with a login or registration form.
Hide Content On Single Post & Archives
Here’s the single post view for a post in a category which is hidden :
Here’s the archive page view for a post in a category which is hidden :
The code enables you to control the content limit and customize the text and link so you display a registration form, sign up form and redirect to any other internal or external URL.
Register or login to access the code snippets :
Leave a Reply