1

I need to make a private page for subscribers in my Wordpress website I don’t want to use plugins so I’m asking what is better, add the capability to subscribers to read private pages or maybe create a custom page template with conditions?

3

You can do it without plugins, you just have to allow subscribers to see Private posts and pages, depending on what you want, so you have to put this code in your functions.php

$subRole = get_role( 'subscriber' );
$subRole->add_cap( 'read_private_posts' );
$subRole->add_cap( 'read_private_pages' );

And then simply create a private post or page and it will works as expected. Tested.

5
  • 1
    Great that is what I was thinking, i suppose it is a secure solution as well.
    – pippo
    Aug 10 '18 at 19:57
  • Also do you suggest to use the hook wp_roles_init?
    – pippo
    Aug 10 '18 at 20:15
  • I don't see why would you need it: "After the roles have been initialized, allow plugins to add their own roles." Aug 10 '18 at 20:16
  • 1
    I read on Wordpress.org NB: This setting is saved to the database, so it might be better to run this on theme/plugin activation
    – pippo
    Aug 10 '18 at 20:18
  • 1
    Since you don't want to add new roles I don't see why you need it. Aug 10 '18 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.