title: WordPress how to give access to a page only for subscribers
body: <p>I am trying to give access of the specific page just for my subscriber user role, if someone else with other then subscriber role or non role user want to access to this page redirect them to a custom login page, I tried with below snippet but I think something is wrong with it, can you please help me to fix this</p>
  <p>Example : Restrict access to specific pages</p>
  <pre><code>add_action( 'template_redirect', function() {
  
      // Get global post
      global $post;
  
      // Prevent access to page with ID 1052
      $page_id = 1052;
      if ( is_page() &amp;&amp; ( $post-&gt;post_parent == $page_id || is_page( $page_id ) ) ) {
  
          // Set redirect to true by default
          $redirect = true;
  
          // If logged in do not redirect
          // You can/should place additional checks here based on user roles or user meta
          if ( current_user_can( 'subscriber' ) || !is_user_logged_in()) {
              $redirect = false;
          }
  
          // Redirect people without access to login page
          if ( $redirect ) {
              wp_redirect( get_site_url().'/custom-url-login' ); exit;
          }
  
  
      }
  
  } );
  </code></pre>