Web Hosting
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress Reply To: How to redirect Private Pages to Home Page?

Discussion in 'Misc WordPress Requests' started by Achyuth Ajoy, Oct 8, 2017.

  1. Achyuth Ajoy

    Guest

    Reply To: How to redirect Private Pages to Home Page?, by Achyuth Ajoy

    Hi,
    Paste the code below to your theme’s functions.php file. It will redirect private pages to homepage, if not logged in.

    function redirect_private_content() {
    global $wp_query, $wpdb;
    if ( is_404() ) {
    $current_query = $wpdb->get_row($wp_query->request);
    if( 'private' == $current_query->post_status ) {
    wp_redirect( home_url('/') );
    exit;
    }
    }
    }
    add_action( 'template_redirect', 'redirect_private_content', 9 );

    Reply To: How to redirect Private Pages to Home Page?
     
    #1

Share This Page

Web Hosting