Support » Fixing WordPress » Restrict a page to logged on users

  • Resolved talytabnel

    (@talytabnel)


    How can I restrict a page to users (logged on). I don’t see the need for a plugin, as that’s all I need to do.
    I also do not want to use the rules as I’ve edited those for the CMS (editor).
    Short Code?
    Any help is appreciated.
    Taly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,
    You can try with below code to restrict a page to a logged in user.

    
    if ((is_user_logged_in()) && is_page('Goals')){
    	wp_redirect( home_url() );
    	exit;
    }
    

    You can also add below condition to the above code
    current_user_can( 'edit_user', $user_id )
    Thanks.

    talytabnel

    (@talytabnel)

    Hi……
    Thanks for that.
    I thought it was out there somewhere but couldn’t find it or remember where!

    Thanks again.
    Taly

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.