Page content only visible to logged in users – WordPress

Do you want to create a page only visible for logged-in users?

In my project I wanted to give access to certain pages to only subscribed users in my WordPress site. I also wanted to show the login form in the page so the users didn’t need to access through your-site.com/wp-admin

Create a Page Template

First things first, let’s create a Page Template so we can assign it to any page we want.

Follow the Codex instructions: http://codex.wordpress.org/Page_Templates

Adding the login form

Alright, now that you have your “Private” custom Page template let’s edit it.

In order to show the login form in WordPress we can use this little trick:

This snippet will show the login form and, once the user enters the credentials, redirect to the same page showing the content.

5 comments

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*