0

Is there a plugin or a function code I can use to restrict pages except the home/static page to my visitors?

I want my visitor to view Home/Static Page ONLY and if they click to older posts (page 2 and so on) they will be redirected to the login page.

Any help is greatly appreciated.

0

Set your posts/pages as "password protected". In the Publish box when editing/creating a post, change the visibility from public to password protected

UPDATE You'll need to use some rewrite rules to redirect everything to the root URL. The first condition redirects everything to the root URL, the second condition adds exceptions for images, css, javascript and for the wp-admin folder. Add this to your .htaccess file

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L,NE]

RewriteCond %{REQUEST_URI} !\.(?:jpe?g|gif|bmp|png|tiff|css|js)$ [NC]
RewriteRule !^wp-admin / [L,NC,R=302]
  • Just a note that what you are trying to achieve is probably not going to be good for SEO – cameronjonesweb Jul 14 '15 at 23:35
  • Thank you user1672694 for your response. Is there a way to do it without having to create password protected page? My blog is set up where any members can create their own posts. I just want to restrict posts/page that are not on the static page. – aeolusgem Jul 14 '15 at 23:39
  • @aeolusgem then you'll need to use .htaccess rewrites. see updated answer – cameronjonesweb Jul 14 '15 at 23:53
0

The following code will redirect any page except homepage to login page.

function my_redirect(){
    if ( in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ){
       return;
    }
    if(!is_home() || !is_front_page()){
        wp_redirect( wp_login_url() ); 
        exit;
    }
}
add_action('init','my_redirect');

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.