Title: Redirect(s)
Last modified: April 9, 2017

---

# Redirect(s)

 *  Resolved [islp](https://wordpress.org/support/users/islp/)
 * (@islp)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/redirects-31/)
 * Hello, I used your plugin mainly because it automatically redirects users to 
   home page when they log from the login area.
 * Problem is I had another requirement and I added the following lines to single.
   php:
 * if(!is_user_logged_in()){
    wp_safe_redirect(wp_login_url(get_post_permalink()));
   exit();}else{get_header();}
 * If I deactivete your plugin, this perfectly works and the user is redirected 
   to the standard login page and, afterwards, to the “private” content he was trying
   to access.
 * If your plugin is active, after user logs, he goes directly to the home page.
 * Is there any way to have both functionalities? What I need is basicly this:
 * I want to restrict the access of some areas of my WordPress blog only to logged
   in users. In particular, I want to restrict ALL the posts and SOME pages: when
   a non-logged-in user tries to access the protected content, he should be redirected
   to the standard login page and, once logged in, he should be redirected to the
   content he was previously tried to access.

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Matt Biscay](https://wordpress.org/support/users/skyminds/)
 * (@skyminds)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/redirects-31/#post-9013677)
 * Hi islp,
 * The correct way to do it would be to put your `if` statement around `the_content()`
   in your template file.
 * Something along these lines :
 *     ```
       // user not logged in : display login link
       if( !is_user_logged_in() ) :?>
       <a href="<?php echo wp_login_url( get_permalink() ); ?>">Login to view content</a>
       <?php
       else: // user is logged in, display content
       the_content();
       endif;
       ```
   
 *  Thread Starter [islp](https://wordpress.org/support/users/islp/)
 * (@islp)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/redirects-31/#post-9013691)
 * This is ok from a dev perspective but, as a user, I prefer redirection to the
   login area (and back to the content), not another link to click
 *  Plugin Author [Matt Biscay](https://wordpress.org/support/users/skyminds/)
 * (@skyminds)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/redirects-31/#post-9013722)
 * How do you login to your login area ? Do you click on a link ? If so, just append
   the `?redirect_to=/wp-admin/` variable to your login link and you can do away
   with the plugin.
 *  Thread Starter [islp](https://wordpress.org/support/users/islp/)
 * (@islp)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/redirects-31/#post-9013737)
 * Matt, in general, right now, I need the following behavior:
 * 1. from the home, when a user clicks the **login** link, once logged in, he should
   be redirected to the home;
 * 2. from the home page, when a user clicks an **admin** link, he should access
   the admin area;
 *  Thread Starter [islp](https://wordpress.org/support/users/islp/)
 * (@islp)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/redirects-31/#post-9013808)
 * Anyway, the redirect_to suggestion works, thank you very much 🙂
 *  Plugin Author [Matt Biscay](https://wordpress.org/support/users/skyminds/)
 * (@skyminds)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/redirects-31/#post-9013821)
 * You’re welcome – don’t forget to rate the plugin 🙂
 *  Thread Starter [islp](https://wordpress.org/support/users/islp/)
 * (@islp)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/redirects-31/#post-9013840)
 * Ok, meantime thanks for you patience and kindness

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Redirect(s)’ is closed to new replies.

 * ![](https://ps.w.org/sky-login-redirect/assets/icon-256x256.png?rev=1141443)
 * [Sky Login Redirect](https://wordpress.org/plugins/sky-login-redirect/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/sky-login-redirect/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/sky-login-redirect/)
 * [Active Topics](https://wordpress.org/support/plugin/sky-login-redirect/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/sky-login-redirect/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/sky-login-redirect/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [islp](https://wordpress.org/support/users/islp/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/redirects-31/#post-9013840)
 * Status: resolved