This code enables you to limit the content on single posts & pages to logged out users.
You can limit the content simply by using a character limit in the code.
The full content will only be displayed for logged in users.
And a login form will display after the content limit for logged out users on single posts and pages only.
The code is very flexible and enables you to easily modify the conditional tags and character limit. You can also use the code for custom post types.
Here’s an example of what logged out users see:
And here’s what logged in users see:
Simply as that. All you need to do is copy & paste the PHP code to the end of your child themes functions file and change the styling of your login form if desired.
The code works in any theme as it uses a WordPress hook and has been tested using the Genesis Sample child theme by StudioPress.
The solution in this tutorial is based on this question from a members of the StudioPress Community Forums:
Hi, Just setting up a new blog and we want to display the header and either the first couple of line of each blog or an excerpt to all users but only display the full articles to logged in users.
Here’s the code for logged in members: