1

Im currently using a theme that has template pages, and they notified me that I cannot use any page restriction plugins, as for that would only work on the default template page. Id like to restrict a certain page, for non logged in users, and they said I must try and use the "is user logged in" function on that specific page. Id like to redirect non logged in users to the login page, and once logged in, they will be able to view that pages content...

Would something like this work?

Any help would be gladly appreciated!

1

You can check for if a user is logged in or not by is_user_logged_in() if logged in then show the page if not then redirect them. Perfect hook to use for this template_redirect.

Example

function check_and_redirect(){

   if( is_page( 45 ) && !is_user_logged_in() ) {
    wp_redirect( wp_login_url() );
    exit();
    }

}
add_action('template_redirect', 'check_and_redirect');

is_page() is used to check for specific pages, you can use page title, slug.

-3

You need a plugin that will conditionally show a menu item. There a few out there. Here is one of them

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.